Ransackで
(col1 LIKE "%hogehoge%" OR col2 LIKE "%hogehoge%") AND (col1 LIKE "%hogehoge%" OR col2 LIKE "%hogehoge%")
のようにcondition同士をANDでつなげる方法を調べていて、日本語ネタが見つからなかったのでメモ書き。
Ransackは関連テーブルをouter joinしてくれたり、エスケープしてくれたりして便利。
{
combinator: 'and',
groupings: {
'0' => {'col1_or_col2_cont' => 'hogehoge'},
'1' => {'col1_or_col2_cont' => 'hogehoge'}
}
}
ActiveRecordってORが入ると文字列かArelでcondition組まないといけないの大変だなぁ
ActiveRecordでORメソッドチェインはやく実装されないかな〜
https://github.com/rails/rails/pull/16052
https://github.com/olivierlacan/ask/issues/4
参考
https://github.com/activerecord-hackery/ransack/issues/169
https://github.com/activerecord-hackery/ransack#grouping-queries-by-or-instead-of-and