1
我想在创建Organization
期间使用accepts_nested_attributes_for
创建User
。我的问题是创建Organization
(假定它有有效的信息),甚至当嵌套User
信息无效。Mongoid acceptable_nested_attributes_for当孩子无效时保存父母
我的模式是这样的:
class Organization
include Mongoid::Document
attr_accessible :name, :users_attributes
field :name, :type => String
has_many :users, dependent: :destroy
accepts_nested_attributes_for :users, :limit => 1
validates_presence_of :name
end
class User
include Mongoid::Document
authenticates_with_sorcery!
attr_accessible :email, :password, :password_confirmation
field :email, type: String
validates_confirmation_of :password, :if => :password
validates_presence_of :password, :on => :create
validates :password, :length => { :minimum => 6 }
validates_presence_of :password_confirmation, :if => :password
validates_presence_of :email
validates_uniqueness_of :email
belongs_to :organization
end
所以基本上,我通过一个有效的组织和无效用户。最终的结果是,尽管用户信息无效,组织仍可以正确创建。思考?