mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Skip collection ids reader optimization if using :finder_sql
This commit is contained in:
parent
5366e61458
commit
838cb1aa50
2 changed files with 8 additions and 1 deletions
|
@ -1296,7 +1296,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
define_method("#{reflection.name.to_s.singularize}_ids") do
|
||||
if send(reflection.name).loaded?
|
||||
if send(reflection.name).loaded? || reflection.options[:finder_sql]
|
||||
send(reflection.name).map(&:id)
|
||||
else
|
||||
send(reflection.name).all(:select => "#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").map(&:id)
|
||||
|
|
|
@ -853,6 +853,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|||
assert !company.clients.loaded?
|
||||
end
|
||||
|
||||
def test_get_ids_for_unloaded_finder_sql_associations_loads_them
|
||||
company = companies(:first_firm)
|
||||
assert !company.clients_using_sql.loaded?
|
||||
assert_equal [companies(:second_client).id], company.clients_using_sql_ids
|
||||
assert company.clients_using_sql.loaded?
|
||||
end
|
||||
|
||||
def test_assign_ids
|
||||
firm = Firm.new("name" => "Apple")
|
||||
firm.client_ids = [companies(:first_client).id, companies(:second_client).id]
|
||||
|
|
Loading…
Reference in a new issue