タグ

関連タグで絞り込む (1)

タグの絞り込みを解除

railsに関するkazu0620のブックマーク (2)

  • Rails4で多対多のリレーションをモデルに実装する - Rails Webook

    Railsでは、ActiveRecordのhas_manyかhas_and_belongs_to_manyを使うことで、DBの「多対多」のテーブル間の関連をモデルに簡単に実装することができます。 ※has_manyとhas_and_belongs_to_manyの違い 多対多関係を作るには、中間テーブルを作成する必要があります。 has_manyの場合、中間テーブルを表現するクラスを作らないといけないが、その中間テーブルに属性やバリデーションなどを追加できます。 has_and_belongs_to_manyの場合、中間テーブルのクラスを作らなくて良いが、中間テーブルにカスタマイズができません。 個人的には、そこまで手間ではないので、has_manyで拡張性をもたせた方がよいと思います。 動作確認 Rails 4.1 ActiveRecord 4.1 目次 多対多関連とは マイグレーション

    Rails4で多対多のリレーションをモデルに実装する - Rails Webook
  • Ruby on Rails Tutorial

    receive announcement and update emails? Get occasional notifications about things like product discounts, blog posts, and new or updated tutorials. Unsubscribe at any time. No thanks.

    Ruby on Rails Tutorial
  • 1