Permalink
Browse files

Skip collection ids reader optimization if using :finder_sql

  • Loading branch information...
1 parent 5366e61 commit 838cb1aa507746b3562931bb63cf4f474363e17a @jeremy jeremy committed Oct 24, 2008
@@ -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)
@@ -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]

0 comments on commit 838cb1a

Please sign in to comment.