我可以做一个“in”吗? Rails 3 中使用 searchlogic/metasearch 传递数组进行搜索?
我正在使用acts_as_network gem,它允许我通过“User.friends”获取用户的所有朋友
我想创建一个“朋友提要”,通过搜索事件记录来显示所有朋友的所有最近事件:
Event | giver_id | receiver_id | date |
概念上我希望能够做到这一点:
feed = Events.giver_id_or_receiver_id_in(User.friends).date_gt(Date.today.2.weeks.ago)
这应该给我一个所有事件的数组,其中giver_id或receiver_id位于朋友数组(User.friends)中,创建于最后两周。
我该怎么做?
I am using the acts_as_network gem which allows me to get all the friends for a User through '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.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IN 查询可以通过以下方式完成: where(:giver_id => array)
所以我认为您可以执行以下操作:
然后您可以将范围与查询的其余部分链接起来:
IN queries can be done with: where(:giver_id => array)
So I think you can do something like:
You can then chain the scope with the rest of your query: