日報
18.2 モデルにおけるリレーションシップの指定
1対1
- has_one
- belongs_to
1対多のリレーションシップ
- has_many
多対多のリレーションシップ
- has_and_belongs_to_many
18.3 belongs_toとhas_xxx宣言
belongs_to
- product(force_reload=false)
- product=obj
- build_product(attributes=)
- create_product(attributes=)
has_many宣言
メソッド
- orders(force_reload=false)
- orders<
- orders.push(order1,,,)
- orders.replace(order1,,,)
- orders.delete(order1,,,)
- orders.delete_all(
- orders.destroy_all(
- orders.clear
- orders.find(options)
- orders.count(options)
- orders.size
- orders.length
- orders.empty?
- orders.sum(options)
- orders.unique
- orders.build(attributes)
- orders.create(attributes)
has_and_belongs_to_many宣言
結合テーブルとしてのモデルの使用
- 重複の削除
has_manyにunique=>trueの適用