Skip to content

Commit

Permalink
Add test to show use of recursive_on_duplicate_key_update with nested…
Browse files Browse the repository at this point in the history
… associations.
  • Loading branch information
ramblex authored and jkowens committed May 17, 2024
1 parent 133d848 commit 18d5c50
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/support/shared_examples/recursive_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ def should_support_recursive_import
assert_equal new_author_name, book.author_name
end
end

it "updates nested associated objects" do
new_chapter_title = 'The Final Chapter'
book = new_topics.first.books.first
book.author_name = 'Richard Bachman'

example_chapter = book.chapters.first
example_chapter.title = new_chapter_title

assert_nothing_raised do
Topic.import new_topics,
recursive: true,
on_duplicate_key_update: [:id],
recursive_on_duplicate_key_update: {
books: { conflict_target: [:id], columns: [:author_name] },
chapters: { conflict_target: [:id], columns: [:title] }
}
end
assert_equal new_chapter_title, Chapter.find(example_chapter.id).title
end
end
end

Expand Down

0 comments on commit 18d5c50

Please sign in to comment.