This project is archived and is in readonly mode.
Efficient include breaks when using finder_sql
Reported by Joshua Bates | April 17th, 2008 @ 08:13 PM
The efficient include? for association collections introduced in e223216e9ac496d4dad53c7ada1406e9e15fbb55 breaks when the association uses finder_sql.
This test
def test_include_checks_if_record_exists_if_target_not_loaded_and_uses_finder_sql
firm = companies(:first_firm)
client = firm.clients_using_sql.first
firm.reload
assert ! firm.clients_using_sql.loaded?
assert_queries(1) do
assert firm.clients_using_sql.include?(client)
end
assert ! firm.clients_using_sql.loaded?
end
Produces this error
test_include_checks_if_record_exists_if_target_not_loaded_and_uses_finder_sql(HasManyAssociationsTest):
ActiveRecord::StatementInvalid: Mysql::Error: Operand should contain 1 column(s): SELECT `companies`.id FROM `companies` WHERE (`companies`.`id` = 3) AND (SELECT * FROM companies WHERE client_of = 1) AND ( (`companies`.`type` = 'Client' OR `companies`.`type` = 'SpecialClient' OR `companies`.`type` = 'VerySpecialClient' ) ) LIMIT 1
Heres a patch that fixes it http://github.com/joshuabates/ra...
Comments and changes to this ticket
-
Repository April 23rd, 2008 @ 09:23 AM
- State changed from new to resolved
(from [b6aa0e13b4e590b82550a6464924f431e57229df]) Fix include? on has_many collections with finder_sql to fall back to Array include? rather than try to use SQL.
[#18 state:resolved]
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>