Permalink
Browse files

Fixed issue where the parent record in a one to many relationship had…

… not been saved causing validation errors when saving child records
  • Loading branch information...
michael-harrison committed Jul 15, 2012
1 parent 1635047 commit 0fc35f941fa39289aa88e72bc0f8867c30276e54
Showing with 16 additions and 16 deletions.
  1. +15 −15 lib/xml_active.rb
  2. +1 −1 lib/xml_active/version.rb
View
@@ -110,6 +110,21 @@ def one_from_xml(source_xml, options = [])
unless active_record.nil?
+ # Process the attributes
+ if options.include? :update or options.include? :sync or options.include? :create
+ assign_attributes_from current_node, :to => active_record
+ end
+
+ # Save the record
+ if options.include? :sync
+ # Doing complete synchronisation with XML
+ active_record.save
+ elsif options.include?(:create) and active_record.new_record?
+ active_record.save
+ elsif options.include?(:update) and not active_record.new_record?
+ active_record.save
+ end
+
# Check through associations and apply sync appropriately
self.reflect_on_all_associations.each do |association|
foreign_key = foreign_key_from(association)
@@ -184,21 +199,6 @@ def one_from_xml(source_xml, options = [])
raise "unsupported association #{association.macro} for #{association.name } on #{self.name}"
end
end
-
- # Process the attributes
- if options.include? :update or options.include? :sync or options.include? :create
- assign_attributes_from current_node, :to => active_record
- end
-
- # Save the record
- if options.include? :sync
- # Doing complete synchronisation with XML
- active_record.save
- elsif options.include?(:create) and active_record.new_record?
- active_record.save
- elsif options.include?(:update) and not active_record.new_record?
- active_record.save
- end
end
active_record
@@ -1,3 +1,3 @@
module XmlActive
- VERSION = "0.0.4"
+ VERSION = "0.0.5"
end

0 comments on commit 0fc35f9

Please sign in to comment.