Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #7859 from ernie/fix-collection-associations-with-…
…select

Fix has_many assocation w/select load after create
  • Loading branch information
tenderlove committed Oct 10, 2012
2 parents 1c534c6 + 9f3b8cd commit 269adae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -414,7 +414,7 @@ def merge_target_lists(persisted, memory)
persisted.map! do |record|
if mem_record = memory.delete(record)

(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

Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/associations/join_model_test.rb
Expand Up @@ -231,6 +231,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_nothing_raised do
assert_equal ernie, category.authors_with_select.detect {|a| a.name == 'Ernie'}
end
end

def test_include_has_many_through
posts = Post.all.merge!(:order => 'posts.id').to_a
posts_with_authors = Post.all.merge!(:includes => :authors, :order => 'posts.id').to_a
Expand Down

0 comments on commit 269adae

Please sign in to comment.