0

I need a way of conditioning a scope so that it checks if a value exists in one of three columns. This is my not code, I have just been told to edit it so it's hard to understand.

So, my condition in MYSQL would be:

WHERE `sub_client_1_id` = 53 OR `sub_client_2_id` = 53 OR `sub_client_3_id` = 53

I tried the following:

sphinx_scope(:by_sub_client){ |id| {:condition => "`sub_client_1_id` = #{id} OR `sub_client_2_id` = #{id} OR `sub_client_3_id` = #{id}" }}

But that doesn't work.

Stefan Dunn
  • 5,363
  • 7
  • 48
  • 84
  • why not use the `where` method e.g. `where("sub_client_1_id = :id OR sub_client_2_id = :id OR sub_client_3_id = :id", id: id)` – engineersmnky Sep 17 '14 at 14:58
  • Which version of Thinking Sphinx are you using? And are these three columns attributes in your Sphinx index definition? – pat Sep 17 '14 at 23:00

0 Answers0