On 5 Nov 2008, at 04:48, linojon wrote:
>
> 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
> linoj
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---