Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass array to where #200

Open
jonasfrey opened this issue Jan 11, 2019 · 6 comments
Open

pass array to where #200

jonasfrey opened this issue Jan 11, 2019 · 6 comments

Comments

@jonasfrey
Copy link

instead of
$query->where("post_id" , 1)->where("category_id" , 2);

i would like to

$query->where([
"post_id" => 1, 
"category_id" => 2
]);

Edit:

i extendet the code by myself:
src/Pixie/QueryBuilder/QueryBuilderHandler.php
between line 608 and 609 i inserted

        //if an array is given 
        if(is_array($key)){
            foreach($key as $key => $value){
                $cached = $this->where($key, $value);
            }
            return $cached;
        } 
@eL-Prova
Copy link

I believe your suggestion is not improving the code directly. The way of defining the where is something personal. I like to see the where in multiple lines because its more clear how many wheres I am using.

@jonasfrey
Copy link
Author

yeah thats your opinion

@TCB13
Copy link

TCB13 commented Jan 14, 2019

I'm with @eL-Prova on this.

@ashickur-rahman
Copy link

I would like have the same thing.

@tooBot
Copy link

tooBot commented Dec 29, 2020

I think, current version is more read, then u propose. U unlikely transfer more then 2-3 parameters to query. Why use an array?

@dragonattack
Copy link

Common use for this is checking if the record exists:

$insert = [
  'name' => 'John',
  'age' => 35,
  'sex' => 'Y',
  etc...
];

if (!QB::table('my_table')->where($insert)->first())
  QB::table('my_table')->insert($insert);

So this makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants