Browse files

Merge pull request #7925 from ernie/3-2-fix-collection-associations-w…

…ith-select

Fix has_many assocation w/select load after create
  • Loading branch information...
2 parents eefb344 + 990a938 commit 84c37741e005b3ac6807be1caf5255c041f12693 @rafaelfranca rafaelfranca committed Oct 12, 2012
View
6 activerecord/CHANGELOG.md
@@ -1,5 +1,11 @@
## Rails 3.2.9 (unreleased)
+* Fix deprecation notice when loading a collection association that
+ selects columns from other tables, if a new record was previously
+ built using that association.
+
+ *Ernie Miller*
+
* The postgres adapter now supports tables with capital letters.
Fix #5920
View
2 activerecord/lib/active_record/associations/collection_association.rb
@@ -409,7 +409,7 @@ def merge_target_lists(persisted, memory)
if mem_index
mem_record = memory.delete_at(mem_index)
- (record.attribute_names - mem_record.changes.keys).each do |name|
+ ((record.attribute_names & mem_record.attribute_names) - mem_record.changes.keys).each do |name|
mem_record[name] = record[name]
end
View
8 activerecord/test/cases/associations/join_model_test.rb
@@ -236,6 +236,14 @@ def test_has_many_with_piggyback
assert_equal "2", categories(:sti_test).authors_with_select.first.post_id.to_s
end
+ def test_create_through_has_many_with_piggyback
+ category = categories(:sti_test)
+ ernie = category.authors_with_select.create(:name => 'Ernie')
+ assert_not_deprecated do
+ assert_equal ernie, category.authors_with_select.detect {|a| a.name == 'Ernie'}
+ end
+ end
+
def test_include_has_many_through
posts = Post.find(:all, :order => 'posts.id')
posts_with_authors = Post.find(:all, :include => :authors, :order => 'posts.id')

0 comments on commit 84c3774

Please sign in to comment.