This project is archived and is in readonly mode.

#18 ✓resolved
Joshua Bates

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

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>

People watching this ticket

Pages