Skip to content

Commit

Permalink
Fixed issue where the parent record in a one to many relationship had…
Browse files Browse the repository at this point in the history
… not been saved causing validation errors when saving child records
  • Loading branch information
Michael Harrison committed Jul 15, 2012
1 parent 1635047 commit 0fc35f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions lib/xml_active.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/xml_active/version.rb
@@ -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.