Translate

2013年10月18日金曜日

FuelPHPのModel::query()でちょっとだけ複雑なクエリを組み立てる

こんな内容のSQLを組み立てたい時、
select * from table \
where (column1 = 'val11' and column2 = 'val12') \
or (column1 = 'val21' and column2 = 'val22')
こんな感じで記述。
$result = Model_Table::query()
    ->and_where_open()
       ->where('column1', '=', 'var11')
       ->where('column2', '=', 'val12')
    ->and_where_close()
    ->or_where_open()
        ->where('column1', '=', 'var21')
        ->where('column02', '=', 'val22')
    ->or_where_close();