ruby on rails - ActiveRecord changed? flag doesn't report changes in associated children -
ruby on rails - ActiveRecord changed? flag doesn't report changes in associated children -
i've got next situation activerecord (in rails 2.3.8):
class order < activerecord::base has_many :documents accepts_nested_attributes_for :documents end class document <activerecord::base belongs_to :order end
now, in controller want direct user differently depending on whether or not made changes existing records, e.g.
@order.attributes = params[:order] if @order.changed? # save order # redirect 1 place else # redirect place end
for want utilize changed? flag. turns out @order.changed? not query children.
i tried implement via association proxy method on has_many :documents association, so:
has_many :documents def changed? any? {|doc| doc.changed?} end end
but has unintended side-effect loads associated documents disk, apparently wipes out changes made in nested attributes assignment in @order.attributes = params[:order] either seems intentional design decision in rails, how solve it? or feature gap?
thoughts?
wolf
you might have @ source of nested_records_changed_for_autosave.
it not want, has clues how it. association_instance_get "gets specified association instance if responds :loaded?, nil otherwise."
ruby-on-rails activerecord
Comments
Post a Comment