2014-01-22から1日間の記事一覧
userモデルとcombinationモデルがあるとする。 combinationモデルにはuser_idとtarget_idがあり、userモデルとリレーションを設定したい。 設定 userのmodel has_many :combinations combinationのmodel belongs_to :user belongs_to :target, :class_name =…
Rails4で次のようにActiverecordを書いたら、警告メッセージが表示された。 Post.includes(:comments).where("comments.title = 'foo'") Rails4からは、読み込んだ関連テーブルの値を利用するためには、referencesメソッドで利用することを明示しなければな…