mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use memoization for collection associations ids reader
Fixes #21082 remove extra space
This commit is contained in:
parent
722abe1722
commit
f744d62736
2 changed files with 12 additions and 2 deletions
|
@ -62,8 +62,10 @@ module ActiveRecord
|
|||
record.send(reflection.association_primary_key)
|
||||
end
|
||||
else
|
||||
@association_ids ||= (
|
||||
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
|
||||
scope.pluck(column)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2308,4 +2308,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|||
|
||||
assert_instance_of PostWithErrorDestroying, error.record
|
||||
end
|
||||
|
||||
def test_ids_reader_memoization
|
||||
car = Car.create!(name: 'Tofaş')
|
||||
bulb = Bulb.create!(car: car)
|
||||
|
||||
assert_equal [bulb.id], car.bulb_ids
|
||||
assert_no_queries { car.bulb_ids }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue