Forum: Ruby on Rails ambiguous nested conditions on find

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cd804cfeeea508f6bf2f5487c9ef4aed?d=identicon&s=25 linojon (Guest)
on 2008-11-05 05:49
(Received via mailing list)
Hi, i'm trying to figure out how to do a query with an ambiguous

Lets say Comment belongs_to :article and :user,
and Article :belongs_to :user

How can I find the comments by one user on articles by another user
in one query?

This doesnt work, but is kind of the idea:

     Comment.find :all, :conditions => {'' =>
'Cccc', :article => { '' => 'Aaaa' } }, :include => [:user,
{ :article => :user } ]

81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-05 12:21
(Received via mailing list)
On 5 Nov 2008, at 04:48, linojon wrote:

> This doesnt work, but is kind of the idea:
>     Comment.find :all, :conditions => {'' =>
> 'Cccc', :article => { '' => 'Aaaa' } }, :include => [:user,
> { :article => :user } ]
The table will be aliased, so your conditions need to be something
like :conditions => {'' => 'Cccc', '' =>
'Aaaa'}, :include (or :joins) =>...
It won't actually be aliased_users, however I believe the naming
scheme for the aliases is deterministic, so just have a look at the
query generated to see what table aliases are being generated

This topic is locked and can not be replied to.