Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Skip collection ids reader optimization if using :finder_sql

  • Loading branch information...
commit 838cb1aa507746b3562931bb63cf4f474363e17a 1 parent 5366e61
@jeremy jeremy authored
View
2  activerecord/lib/active_record/associations.rb
@@ -1296,7 +1296,7 @@ def collection_reader_method(reflection, association_proxy_class)
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)
View
7 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -853,6 +853,13 @@ def test_get_ids_for_unloaded_associations_does_not_load_them
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]
Please sign in to comment.
Something went wrong with that request. Please try again.