[英]Active record joins in rails 3.1
尝试返回与特定用户撰写的文章相关的所有评论。 以下代码给了我错误:
undefined method `joins' for #<User:0x000001042c8bc0>
在 Rails 3.1 下
class User
has_many :articles
def comments
self.joins(:articles => :comments)
end
end
你可能想要一个has_many:through
这里。
class User
has_many :articles
has_many :comments, :through => :articles
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.