where_id_in() for selecting multiple records by primary key#202
Merged
treffynnon merged 2 commits intoj4mie:developfrom May 28, 2014
Merged
where_id_in() for selecting multiple records by primary key#202treffynnon merged 2 commits intoj4mie:developfrom
treffynnon merged 2 commits intoj4mie:developfrom
Conversation
Multiple OR'ed conditions
-------------------------
You can add simple ORed conditions to the same WHERE clause using
``where_any_is``. You should specify multiple conditions using an
array of items. Each item will be an associative array that contains
a multiple conditions.
```php
<?php
$people = ORM::for_table('person')
->where_any_is(array(
array('name' => 'Joe', 'age' => 10),
array('name' => 'Fred', 'age' => 20)))
->find_many();
// Creates SQL:
SELECT * FROM `widget` WHERE (( `name` = 'Joe' AND `age` = '10' ) OR ( `name` = 'Fred' AND `age` = '20' ));
```
By default, it uses the equal operator for every column, but it can be
overriden for any column using a second parameter:
```php
<?php
$people = ORM::for_table('person')
->where_any_is(array(
array('name' => 'Joe', 'age' => 10),
array('name' => 'Fred', 'age' => 20)), array('age' => '>'))
->find_many();
// Creates SQL:
SELECT * FROM `widget` WHERE (( `name` = 'Joe' AND `age` > '10' ) OR ( `name` = 'Fred' AND `age` > '20' ));
```
If you want to set the default operator for all the columns, just pass it as
the second parameter:
```php
<?php
$people = ORM::for_table('person')
->where_any_is(array(
array('score' => '5', 'age' => 10),
array('score' => '15', 'age' => 20)), '>')
->find_many();
// Creates SQL:
SELECT * FROM `widget` WHERE (( `score` > '5' AND `age` > '10' ) OR ( `score` > '15' AND `age` > '20' ));
```
treffynnon
added a commit
that referenced
this pull request
May 28, 2014
where_id_in() for selecting multiple records by primary key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allows selecting multiple records by passing an array of primary keys.
I.e.:
It also supports compound primary keys:
Closes #199