簡體   English   中英

活動記錄加入 Rails 3.1

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM