保存父对象时,如何在关联上调用“before_save”回调?例如:
class Company < ActiveRecord::Base
belongs_to :user
before_save Proc.new { ... } # Not called.
end
class User < ActiveRecord::Base
has_one :company
before_save Proc.new { ... } # Gets called.
end
params = {
:user => {
:name => "Kevin Sylvestre",
:company_attributes => { :city => "Waterloo", :region => "Ontario" }
}
}
@user = User.new(params[:user])
@user.save
在用户上调用“before_save”,但在公司上调用。感谢。