鉴于以下情况:
Foo has_many :bars, :through => :baz
和
Foo accepts_nested_attributes_for :bar
我想find_or_create_by_name在添加新的时做一个:bar,但我不知道在哪里可以拥有某种before_add功能。
这个问题的背景是Bar validates_uniqueness_of :name,当我尝试创建一个Foo使用现有Bar.
鉴于以下情况:
Foo has_many :bars, :through => :baz
和
Foo accepts_nested_attributes_for :bar
我想find_or_create_by_name在添加新的时做一个:bar,但我不知道在哪里可以拥有某种before_add功能。
这个问题的背景是Bar validates_uniqueness_of :name,当我尝试创建一个Foo使用现有Bar.