1
0
Fork 0
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:
Mehmet Emin İNAÇ 2015-08-02 04:38:36 +03:00
parent 722abe1722
commit f744d62736
2 changed files with 12 additions and 2 deletions

View file

@ -62,8 +62,10 @@ module ActiveRecord
record.send(reflection.association_primary_key)
end
else
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
scope.pluck(column)
@association_ids ||= (
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
scope.pluck(column)
)
end
end

View file

@ -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