Problem with find with :joins and :include in same call

Hi all,

I am investigating moving our app from Rails 2.2.2 to Rails 2.3.2. So
far doesn’t look too bad, but I am running in to one problem.

In a model I have the following named scope:
named_scope :valid, {:include => :broker, :joins => ‘INNER JOIN
payers ON payers.customer_id = brokers.id AND
payers.customer_type = ‘Broker’’, :conditions => "payers.status =
‘active’ and ticket_sets.delete_flag = 0 and ticket_sets.qty > 0 and
(brokers.ei_id is NULL or (brokers.ei_id is not null and
ticket_sets.ei_id is not null)) "}

This worked perfectly in Rails 2.2.2, but in Rails 2.3.2 this blows up.

Looking at the log file, it appears that the :include clause isn’t being
parsed.

SELECT ticket_sets.* FROM ticket_sets INNER JOIN payers ON
payers.customer_id = brokers.id AND payers.customer_type =
‘Broker’ WHERE (payers.status = ‘active’ and ticket_sets.delete_flag =
0 and ticket_sets.qty > 0 and (brokers.ei_id is NULL or (brokers.ei_id
is not null and ticket_sets.ei_id is not null)) )

If I remove the the joins clause, the brokers get included like they
should be, but it doesn’t have payers referenced.

One option would be into use nested includes to include the payers; but
this has some serious performance issues. The ticket sets table is large
and we don’t need to the payers data returned, just for selection.

Does anybody have any ideas?

Thanks,

Andrew

On May 10, 8:24 pm, Andrew S. [email protected]
wrote:

One option would be into use nested includes to include the payers; but
this has some serious performance issues. The ticket sets table is large
and we don’t need to the payers data returned, just for selection.

Does anybody have any ideas?

it looks like a bug in the code that determines which include strategy
should be used

Fred

Frederick C. wrote:

On May 10, 8:24�pm, Andrew S. [email protected]
wrote:

One option would be into use nested includes to include the payers; but
this has some serious performance issues. The ticket sets table is large
and we don’t need to the payers data returned, just for selection.

Does anybody have any ideas?

it looks like a bug in the code that determines which include strategy
should be used

Fred

Fred,

Do you want me to file a bug at lighthouse?

Thanks,

Andrew

Filed at Lighthouse as #2631.

i think only include or joins should be used not both…

On Mon, May 11, 2009 at 1:18 AM, Andrew S. <

On May 11, 3:13 pm, Lakshmi N. [email protected] wrote:

i think only include or joins should be used not both…

in general, nothing wrong with using both (for distinct associations -
wouldn’t want to include and join the same association)

Fred