Rails - Searchlogic 将搜索条件作为值数组
我有两个模型 Employee 和单位。 单位有许多员工。我正在使用 SearchLogic 来搜索员工模型。 Searchlogic 中以下 SQL 的等价物是什么
employees.unit_id IN (1,2,3)
我都尝试过
unit_id_equals_all[]
unit_id_equals_any[]
但没有任何作用。有人可以帮忙吗?
谢谢,阿比拉什
I have two models Employee & Unit. Unit has many Employees. I am using SearchLogic to search employee model. What is the equivalent of below SQL in Searchlogic
employees.unit_id IN (1,2,3)
I have tried both
unit_id_equals_all[]
unit_id_equals_any[]
But nothing works. Can anyone help?
Thanks, Abhilash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里同样的问题。
我不知道为什么这对我有用,或者为什么我什至尝试过它,因为它没有记录。但我将 _equals 更改为 _in,它生成了带有 IN 的 SQL,并且运行良好。
Same problem here.
I have no idea why this worked for me, or why I even tried it, since it is undocumented. But I changed the _equals to _in, and it produced the SQL with IN, and worked perfectly.
我们在 Rails 2.3.12 项目中也遇到了同样的问题。使用 searchlogic 2.4.7,我们可以这样做:
升级到 searchlogic 2.5.8 后(旧版本中的弃用消息使 cucumber 和规范输出变得混乱),这种语法不再有效。它抛出了这个错误,就像上面的错误一样:
在尝试了上面的解决方案之后,我们发现这两种语法替代方案有效:
换句话说,如果没有“_any”,新的搜索逻辑会产生无效的 mysql.txt 文件。研究何时以及为何发生此更改,我发现了此提交讨论:
Github 提交更改处理数组
这一更改和讨论的结果是,当您想要与数组中的任何值进行匹配时,需要 _any ,否则只需将数组直接传递到 equals 语句,而不将 SQL 更改为“ IN” 根据需要获得多个值。
恢复到 2.4.7 可清除错误。为了避免弃用错误,我们最终将所有调用更改为更明确的 _any 或 _in。希望这会有所帮助,并补充上面非常有用的答案。
We had this same issue with a Rails 2.3.12 project. With searchlogic 2.4.7 we could do:
After upgrading to search logic 2.5.8 (deprecation messages in the old one were cluttering out cucumber and spec output), this syntax no longer worked. It threw this error just like the one above:
After trying the solutions above, we found that these two syntax alternatives worked:
In other words, without the "_any" the new search logic produces invalid mysql. Looking into when and why this change might have occurred, I found this commit discussion:
Github commit changing handling of arrays
The upshot of this change and the discussion was to require _any for times when you want a match against any value in the array, and otherwise just pass the array in to the equals statement directly without changing the SQL to "IN" as needed for multiple values.
Reverting to 2.4.7 clears the error. Changing all the calls to the more explicit _any or _in is what we ended up doing in order to avoid deprecation errors. Hope this helps and adds to the very helpful answers above.