I have 2 models with nested data:
class Goodtender
include Mongoid::Document
include Mongoid::Timestamps
field :name
field :count
references_many(:offerprices, :autosave => true)
accepts_nested_attributes_for :offerprices, :allow_destroy => true, :reject_if => :all_blank
validates_presence_of :name, :message => "Invalid"
validates_numericality_of :count, :message => 'Invalid'
validates_associated :offerprices, :message => 'Invalid'
end
class Offerprice
include Mongoid::Document
include Mongoid::Timestamps
field :summ
field :date_delivery, :type => DateTime
field :note
referenced_in :goodtender, :class_name => 'Goodtender'
validates_presence_of :date_delivery, :message => "Invalid"
validates_numericality_of :summ, :message => 'Invalid'
end
When making nested records, correct validation takes place, for example, if data in nested model do not correct, so command:
@tender = Tender.new(params[:tender])
@tender.save
returns false
but if update data:
@tender = Tender.find(params[:id])
@tender.update_attributes(params[:tender])
always eturns true
Even if nested data do not valid. Here parent's data updates and valids and if parents' data does not valid returns false, if one of the nested record does not valid, they are ignored when you are saving and update_attributes returns true. Is there the opportunity to check data on validity in the time of updating all the nested data chain? Thank you for your respond.
I'm using: Ruby 1.8.7 RoR 3.0.9 Mongoid 2.0.1