On Wed, Jun 17, 2009 at 11:31 AM, Pratik <[email protected]> wrote:
> Not really. You can already specify associations in :joins arguments. So
> your example would be :
>
> Lunch.find(:all, :left_joins => :pies, :conditions => {:pies => {:steak
> => true}})
>
Ah, when you said "Make user explicitly specify the required joins if they
want to put conditions on the associations" I thought you were suggesting
getting rid of that - I interpreted that as saying that you would have to
write out the join conditions.
No worries then, I like what you're suggesting.
But just to clarify, if you write the above statement - a left join, plus
conditions on the joined table, will those conditions work as they currently
do?
I ask because there's a big difference between adding terms into the left
join conditions and adding terms into the overall statement conditions - the
former would exclude the right rows (pies) if the conditions aren't true,
whereas the latter excludes the left rows (lunches) if the conditions aren't
true also.
We only have a way to do the latter at the moment; would it be worth adding
a way to do the former?
Lunch.find(:all, :left_joins => :pies, :conditions => {:pies => {:steak =>
true}})
Would load only lunches that have steak pies currently - meaning that
statement will give just the same results as
Lunch.find(:all, :joins => :pies, :conditions => {:pies => {:steak =>
true}})
Which somewhat defeats the purpose of using a left join - it would be nice
to have a way to load all lunches plus any steak pies that they have, since
that's presumably why you're using a left join in the first place.
(I rate this only a "nice to have" with left joins because admittedly, you
can do this by writing the conditions out as a string instead, and use "OR
pies.id IS NULL". But I think that beginners wouldn't expect to have to do
this every time.)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---