# Ambiguous nested conditions on find

**URL:** <https://www.ruby-forum.com/t/ambiguous-nested-conditions-on-find/152557>\
**Category:** Rails\
**Created:** [November 5, 2008, 5:49am UTC](https://www.ruby-forum.com/t/ambiguous-nested-conditions-on-find/152557 "2008-11-05T05:49:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![linojon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b3f665/32.png) [@linojon](https://www.ruby-forum.com/u/linojon)\
**Post date:** [November 5, 2008, 5:49am UTC](https://www.ruby-forum.com/t/ambiguous-nested-conditions-on-find/152557/1 "2008-11-05T05:49:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![linojon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b3f665/32.png) [@linojon](https://www.ruby-forum.com/u/linojon)\
**Post date:** [November 5, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/ambiguous-nested-conditions-on-find/152557/2 "2008-11-05T12:21:45Z")

</div>

On 5 Nov 2008, at 04:48, linojon wrote:

> 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
