订货我有三个表:复杂的SQL查询的连接表在轨
Posts
Keywordings
Keywords
括号中的相关领域。
一个帖子
has_many :keywordings
has_many :keywords, :through => :keywordings
一个关键字提取(POST_ID,keyword_id)
belongs_to :post
belongs_to :keyword
一个关键字(名称)
has_many :keywordings
has_many :posts, :through => :keywordings
我想找到具有匹配关键字的所有帖子列表中的任何(按名称),按匹配多少个关键字排序。我确信这些都可以在SQL中完成,但我无所适从。
如果我不得不在Ruby中做一些事情,那很好,但最好全部是在SQL中。它必须快速。
这是胜利。我无法编辑,但k.keyword_id应该是k.id,而p.post_id应该是p.id. 它虽然我想要,但这是很重要的。非常感谢! – 2009-12-21 05:42:37