Forum: Ruby on Rails Problem with find with :joins and :include in same call

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D35d964695abd1bac108370eaf001af3?d=identicon&s=25 Andrew Selder (aselder)
on 2009-05-10 21:24
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-10 21:33
(Received via mailing list)
On May 10, 8:24 pm, Andrew Selder <rails-mailing-l...@andreas-s.net>
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
D35d964695abd1bac108370eaf001af3?d=identicon&s=25 Andrew Selder (aselder)
on 2009-05-10 21:34
Frederick Cheung wrote:
> On May 10, 8:24�pm, Andrew Selder <rails-mailing-l...@andreas-s.net>
> 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
D35d964695abd1bac108370eaf001af3?d=identicon&s=25 Andrew Selder (aselder)
on 2009-05-10 21:48
Filed at Lighthouse as #2631.
81ad4b2c219e5f8f9a952e4dddc675db?d=identicon&s=25 Lakshmi Narayana (Guest)
on 2009-05-11 16:14
(Received via mailing list)
i think only include or joins should be used not both..

On Mon, May 11, 2009 at 1:18 AM, Andrew Selder <
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-11 16:54
(Received via mailing list)
On May 11, 3:13 pm, Lakshmi Narayana <lakshis...@gmail.com> 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
This topic is locked and can not be replied to.