我有一个模特&一家工厂。
class User < ActiveRecord::Base
has_one :emergency_contact, dependent: :destroy
has_one :membership, dependent: :destroy
has_one :email_settings, dependent: :destroy
after_create :build_dependencies
def build_dependencies
build_membership
build_emergency_contact
build_email_settings
end
...
end
当我运行FactoryGirl.create :user
时,after_create会运行,但相关的模型不会被构建和保存。
这与User.create...
将构建其他关联的控制台形成对比。