Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Efficient include breaks when using finder_sql

#18

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...

Reported by Joshua Bates · April 17th, 2008 @ 08:13 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Repository
    Repository
    • 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]

    http://github.com/rails/rails/co...

    April 23rd, 2008 @ 09:23 AM