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 creating nested records, the correct check is performed, for example, if the data in the nested model is not adjusted, so the 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 returns true
Even if the attached data is invalid. Here, the parent data updates and valids and if the parent data is invalid, returns false, if one of the nested entries is invalid, they are ignored when saving and update_attributes returns true. Is it possible to check the data for validity while updating the entire nested data chain? Thanks for answering.
I use: Ruby 1.8.7 RoR 3.0.9 Mongoid 2.0.1