【发布时间】:2013-07-26 00:58:36
【问题描述】:
也许这里已经讨论过这样的问题,但我什至无法意识到,如何正确地用谷歌搜索这样的案例。
在 Rails 中,我有以下模型:
用户(has_many book_specimens,has_many Friendship,has_many Friends through Friendship,has_many book through book_specimens)
Book_specimen(belongs_to user,belongs_to book)
书(有_many book_specimens,通过book_specimens拥有_many所有者)
友谊(belongs_to user,belongs_tofriend)
我需要在用户朋友拥有的书籍中搜索书籍。如果打破非sql逻辑,它看起来像
结果 = [];
friends.each 做 |friend|
results.push(Book.search 条件:{title: 'Lorem', owner_id:friend.id})
结束
有什么方法可以在一个命令中完成吗?那我应该如何准备索引呢?
提前致谢。
【问题讨论】:
标签: ruby-on-rails thinking-sphinx