2
嗨,大家好,我知道,这是非常糟糕的主意,但我想加入我的查询三个表上的多态关联加入对多态关联
例如
class Article
has_many :comments, :as=>:commentable
end
class Post
has_many :comments, :as=>:commentable
end
class Comment
belongs_to :commentable, :polymorphic=>:true
end
,我需要得到类似的东西
Comment.all(:joins=>:commentable)
我当然不能写正是这样加入,但我需要的东西,可以加入此三个表
我被几个表写cimplicate搜索用户可以选择不同的选项假设User has_one Comment
,我想选择谁评论的东西(文章或帖子)的所有用户,其中包括一些短语所以我需要类似的东西User.all(:joins=>{:comments=>:commentable}, :conditions=>["articles.body LIKE (?) OR posts.header LIKE (?)", value, value])
它不应该被'Comment'你的第三类?你到底想做什么?也许我们可以建议另一种方式来达到你想要的效果。 – 2010-08-13 19:38:35