Skip to content

Instantly share code, notes, and snippets.

@gaspard
Created February 8, 2009 20:56
Show Gist options
  • Save gaspard/60504 to your computer and use it in GitHub Desktop.
Save gaspard/60504 to your computer and use it in GitHub Desktop.
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 0fefec1..2f5babe 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -101,6 +101,7 @@ module ActiveRecord
else
build_record(attributes) do |record|
block.call(record) if block_given?
+ record.send(:"#{@owner.class.to_s.underscore}=", @owner) if record.respond_to?(:"#{@owner.class.to_s.underscore}=")
set_belongs_to_association_for(record)
end
end
@@ -394,6 +395,9 @@ module ActiveRecord
find(:all)
end
+ records.each do |record|
+ record.send(:"#{@owner.class.to_s.underscore}=", @owner) if record.respond_to?(:"#{@owner.class.to_s.underscore}=")
+ end
@reflection.options[:uniq] ? uniq(records) : records
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment