Hi, i'm trying to figure out how to do a query with an ambiguous condition
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 => {'users.name' => 'Cccc', :article => { 'users.name' => 'Aaaa' } }, :include => [:user, { :article => :user } ]
linoj
Hi, i'm trying to figure out how to do a query with an ambiguous
condition
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 => {'users.name' =>
'Cccc', :article => { 'users.name' => 'Aaaa' } }, :include => [:user,
{ :article => :user } ]
The table will be aliased, so your conditions need to be something
like :conditions => {'users.name' => 'Cccc', 'aliased_users.name' =>
'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
Fred