Last active
December 21, 2015 10:26
-
-
Save mamor/5917446 to your computer and use it in GitHub Desktop.
FuelPHPのORMで複数のorをつなげるサンプル
This file contains 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
Model_Profile::query() | |
->and_where_open()->where('id', 'like', '%foo%')->or_where('user_id', 'like', '%foo%')->and_where_close() | |
->and_where_open()->where('id', 'like', '%bar%')->or_where('user_id', 'like', '%bar%')->and_where_close() | |
->get(); | |
// WHERE (`t0`.`id` LIKE '%foo%' OR `t0`.`user_id` LIKE '%foo%') AND (`t0`.`id` LIKE '%bar%' OR `t0`.`user_id` LIKE '%bar%') | |
Model_Profile::find('all', array('where' => array( | |
// 当たり前だが'or'を複数指定しても最後のしか残らない | |
// ネストすれば検索結果は意図通りになるかもしれないが、求めているクエリの形とは異なってしまう | |
array(array('id', 'like', '%foo%'), 'or' => array('user_id', 'like', '%foo%')), | |
array(array('id', 'like', '%bar%'), 'or' => array('user_id', 'like', '%bar%')), | |
))); | |
// WHERE (`t0`.`id` LIKE '%foo%' OR `t0`.`user_id` LIKE '%foo%') AND (`t0`.`id` LIKE '%bar%' OR `t0`.`user_id` LIKE '%bar%') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment