- バックアップ一覧
- ソース を表示
- バックアップ を表示
- Ruby on Rails/has_manyのdependentオプション は削除されています。
- 1 (2007-01-09 (火) 20:10:34)
- 追加された行はこの色です。
- 削除された行はこの色です。
http://railsapi.masuidrive.jp/module/ActiveRecord::Associations::ClassMethods/has_many
:dependent - if set to :destroy all the associated objects are destroyed alongside
this object by calling their destroy method.
つまり、
class foo < ActiveRecord::Base
has_many :bar, :dependent => :destory
end
のようにしておき、fooのオブジェクトをdestoryすると、barのdestoryも呼び出されるそうです。
If set to :delete_all all associated objects are deleted without calling their
destroy method.
class foo < ActiveRecord::Base
has_many :bar, :dependent => :delete_all
end
だと、fooをdestoryすると、barのdestoryを呼び出さずにdeleteされるそうです。
If set to :nullify all associated objects’ foreign keys are set to NULL without
calling their save callbacks.
class foo < ActiveRecord::Base
has_many :bar, :dependent => :nullify
end
だと、fooをdestoryすると、barのsaveを呼び出すことなく、barのfooへのforeign keyを NULL
にセットするらしいです。
NULL可なりレーションの時の対処ですね。
NOTE: :dependent => true is deprecated and has been replaced with :dependent => :destroy.
:dependent => trueは :dependent => :destoryと同じ。