2015年1月22日のブックマーク (1件)

  • 【Rails】has_many, throughの逆の関連はdelegate, toかhas_one, through

    目次 TL;DRテーブル構成 Railsモデル構成has_many, through の定義 belongs_to, through は使えない?1. delegate を使う方法2. has_one, through を使う方法 includes も使うことができるどちらの方法が良いか?参考TL;DRhas_many+throughの逆の関連の定義には: belongs_to+throughは使えないdelegate or has_one+through が使えるhas_one+through の方が効率もよく、 includes も使えてオススメテーブル構成とあるRailsアプリケーションでこんなテーブル構成があったとします。 Railsモデル構成ユーザー(User)は複数の記事(Post)をもっていて、その記事は複数のコメント(Comment)を持っている、という状態です。 clas

    【Rails】has_many, throughの逆の関連はdelegate, toかhas_one, through
    yuya0120117117
    yuya0120117117 2015/01/22
    through, has_one, delegate