简体   繁体   English

我可以在Rails 3中通过数组进行searchlogic / metasearch的“ in”搜索吗?

[英]Can I do an 'in' search with searchlogic/metasearch in Rails 3 passing an array?

I am using the acts_as_network gem which allows me to get all the friends for a User through 'User.friends' 我正在使用acts_as_network宝石,这使我可以通过“ User.friends”为用户获取所有朋友

I want to create a 'friend feed' showing all the recent events for all of the friends by searching through the Event records where Event: 我想通过在事件记录中搜索以下事件来创建一个“朋友摘要”,以显示所有朋友的所有最近事件:

  Event  | giver_id | receiver_id | date |

Conceptually I'd like to be able to do this: 从概念上讲,我希望能够做到这一点:

feed = Events.giver_id_or_receiver_id_in(User.friends).date_gt(Date.today.2.weeks.ago)

This should give me an array of all events where either the giver_id or receiver_id is IN the array of friends (User.friends), created in the last two weeks. 这应该给我一个所有事件的数组,其中giver_id或receiver_id在最近两个星期内创建的朋友(User.friends)数组中。

How can I do this? 我怎样才能做到这一点?

IN queries can be done with: where(:giver_id => array) IN查询可以通过以下方式完成:where(:giver_id => array)

So I think you can do something like: 因此,我认为您可以执行以下操作:

scope :party_in, lambda {|friends| where(:giver_id => friends) | where(:receiver_id => friend) }

You can then chain the scope with the rest of your query: 然后,您可以将范围与查询的其余部分链接起来:

feed = Events.party_in(User.friends).date_gt(Date.today.2.weeks.ago)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM