Skip to content

Commit cb45ee3

Browse files
committed
Remove the functionality introduce in 28d3390
There are several situations it doesn't cater for, and the inconsistency isn't worth blocking 2.2.
1 parent 4c05055 commit cb45ee3

File tree

3 files changed

+1
-45
lines changed

3 files changed

+1
-45
lines changed

activerecord/lib/active_record/associations.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ def association_accessor_methods(reflection, association_proxy_class)
12351235

12361236
association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
12371237

1238-
if association.nil? || !association.loaded? || force_reload
1238+
if association.nil? || force_reload
12391239
association = association_proxy_class.new(self, reflection)
12401240
retval = association.reload
12411241
if retval.nil? and association_proxy_class == BelongsToAssociation
@@ -1269,17 +1269,6 @@ def association_accessor_methods(reflection, association_proxy_class)
12691269
end
12701270
end
12711271

1272-
if association_proxy_class == BelongsToAssociation
1273-
define_method("#{reflection.primary_key_name}=") do |target_id|
1274-
if instance_variable_defined?(ivar)
1275-
if association = instance_variable_get(ivar)
1276-
association.reset
1277-
end
1278-
end
1279-
write_attribute(reflection.primary_key_name, target_id)
1280-
end
1281-
end
1282-
12831272
define_method("set_#{reflection.name}_target") do |target|
12841273
return if target.nil? and association_proxy_class == BelongsToAssociation
12851274
association = association_proxy_class.new(self, reflection)

activerecord/test/cases/associations/belongs_to_associations_test.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,6 @@ def test_natural_assignment
4747
assert_equal apple.id, citibank.firm_id
4848
end
4949

50-
def test_foreign_key_assignment
51-
# Test using an existing record
52-
signals37 = accounts(:signals37)
53-
assert_equal companies(:first_firm), signals37.firm
54-
signals37.firm_id = companies(:another_firm).id
55-
assert_equal companies(:another_firm), signals37.firm
56-
57-
# Test using a new record
58-
account = Account.new
59-
account.firm_id = companies(:another_firm).id
60-
assert_equal companies(:another_firm), account.firm
61-
end
62-
6350
def test_no_unexpected_aliasing
6451
first_firm = companies(:first_firm)
6552
another_firm = companies(:another_firm)

activerecord/test/cases/associations_test.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,6 @@ def test_failed_reset_returns_nil
182182
assert_nil p.author.reset
183183
end
184184

185-
def test_reset_loads_association_next_time
186-
welcome = posts(:welcome)
187-
david = authors(:david)
188-
author_assoc = welcome.author
189-
190-
assert_equal david, welcome.author # So we can be sure the test works correctly
191-
author_assoc.reset
192-
assert !author_assoc.loaded?
193-
assert_nil author_assoc.target
194-
assert_equal david, welcome.author
195-
end
196-
197-
def test_assigning_association_id_after_reload
198-
welcome = posts(:welcome)
199-
welcome.reload
200-
assert_nothing_raised do
201-
welcome.author_id = authors(:david).id
202-
end
203-
end
204-
205185
def test_reload_returns_assocition
206186
david = developers(:david)
207187
assert_nothing_raised do

0 commit comments

Comments
 (0)