简体   繁体   English

活动记录加入 Rails 3.1

[英]Active record joins in rails 3.1

Trying to return all comments associated with articles written by a particular user.尝试返回与特定用户撰写的文章相关的所有评论。 The following code gives me the error:以下代码给了我错误:

undefined method `joins' for #<User:0x000001042c8bc0>

under Rails 3.1在 Rails 3.1 下

class User
  has_many :articles

  def comments
    self.joins(:articles => :comments)
  end

end

You probably want a has_many:through here.你可能想要一个has_many:through这里。

class User
  has_many :articles
  has_many :comments, :through => :articles
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM