开发者

Active record joins in rails 3.1

开发者 https://www.devze.com 2023-03-21 04:43 出处:网络
Trying to return all comments associated with articles written by a particular user.开发者_如何学C

Trying to return all comments associated with articles written by a particular user.开发者_如何学C The following code gives me the error:

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

under Rails 3.1

class User
  has_many :articles

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

end


You probably want a has_many :through here.

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

精彩评论

暂无评论...
验证码 换一张
取 消