[英]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.