Skip to content

Commit

Permalink
Merge pull request rails#12443 from arthurnn/add_inverse_of_add_target
Browse files Browse the repository at this point in the history
Add inverse of add target
  • Loading branch information
rafaelfranca committed Oct 4, 2013
2 parents 31c79e2 + fc59e99 commit 7ed5bdc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Expand Up @@ -350,6 +350,7 @@ def add_to_target(record)
end

callback(:after_add, record)
set_inverse_instance(record)

record
end
Expand Down
13 changes: 13 additions & 0 deletions activerecord/test/cases/associations/inverse_associations_test.rb
Expand Up @@ -290,6 +290,19 @@ def test_parent_instance_should_be_shared_with_first_n_and_last_n_children
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).secret_interests }
end

def test_child_instance_should_point_to_parent_without_saving
man = Man.new
i = Interest.create(:topic => 'Industrial Revolution Re-enactment')

man.interests << i
assert_not_nil i.man

i.man.name = "Charles"
assert_equal i.man.name, man.name

assert !man.persisted?
end
end

class InverseBelongsToTests < ActiveRecord::TestCase
Expand Down

0 comments on commit 7ed5bdc

Please sign in to comment.