# Ez\_where problems

**URL:** <https://www.ruby-forum.com/t/ez-where-problems/91100>\
**Category:** Rails\
**Created:** [April 4, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/ez-where-problems/91100 "2007-04-04T18:44:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 4, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/ez-where-problems/91100/1 "2007-04-04T18:44:36Z")

</div>

Hi!

I’m having a small problem with ez\_where. I’m sure it’s a simple  
fix…but if anybody can help, that would be excellent.

I’m trying to run one query, and then run another one, sticking the  
results from the first into the results of the second…if that makes  
any sense. Anyways, here is what happens when I use the command line  
console.

> > username = “bob”  
> > =\> “bob”
> 
> > resUser = User.find(:all, :conditions =\> [“username = :name”, {:name =\> username}])  
> > =\> [#\<User:0x36bfb2c @attributes={“created\_on”=\>“2007-03-30 16:11:00”,  
> > “updated\_on”=\>“2007-03-30 16:12:01”, “admin”=\>“1”, “username”=\>“bob”,  
> > “group\_id”=\>“1”, “id”=\>“2”, “email”=\>“smith”}\>, #\<User:0x36bfb04  
> > @attributes={“created\_on”=\>“2007-04-02 11:07:00”,  
> > “updated\_on”=\>“2007-04-02 11:07:00”, “admin”=\>“0”, “username”=\>“bob”,  
> > “group\_id”=\>“2”, “id”=\>“5”, “email”=\>“smith”}\>]
> 
> > cond = Caboose::EZ::Condition.new do  
> > ?\> group\_id === resUser
> 
> > end  
> > =\> #\<Caboose::EZ::Condition:0x36bb9dc @outer=:and, @table\_name=nil,  
> > @inner=:and, @clauses=[#\<Caboose::EZ::Clause:0x36bb8d8 @negate=false,  
> > @case\_insensitive=false, @table\_prefix="", @name=“group\_id”,  
> > @test=:in, @value=[#\<User:0x36bfb2c  
> > @attributes={“created\_on”=\>“2007-03-30 16:11:00”,  
> > “updated\_on”=\>“2007-03-30 16:12:01”, “admin”=\>“1”, “username”=\>“bob”,  
> > “group\_id”=\>“1”, “id”=\>“2”, “email”=\>“smith”}\>, #\<User:0x36bfb04  
> > @attributes={“created\_on”=\>“2007-04-02 11:07:00”,  
> > “updated\_on”=\>“2007-04-02 11:07:00”, “admin”=\>“0”, “username”=\>“bob”,  
> > “group\_id”=\>“2”, “id”=\>“5”, “email”=\>“smith”}\>]\>], @parenthesis=nil\>
> 
> > results = Result.find(:all, :conditions =\> cond.to\_sql)  
> > =\> [#\<Result:0x369aca0 @attributes={“created\_on”=\>nil,  
> > “plugin\_id”=\>“19407”, “scan\_id”=\>“4”, “status”=\>nil, “riskval”=\>“3”,  
> > “msg”=\>"\blahblahblah…"}\>]

This is where it gets strange. Instead of using the group\_id results  
to do the query, it uses the ‘id’ column. In the log, I see this…

SELECT \* FROM results WHERE (group\_id IN (2,5))

2,5 are the primary keys of the row ‘bob’. What I want is the  
‘group\_id’, which is ‘1,2’.

If anybody can help, that would be great.

Thanks in advanced…  
mike

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 5, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/ez-where-problems/91100/2 "2007-04-05T16:39:56Z")

</div>

Hi,

Thanks for the response. I’m sorry, but I’m really a rails newbie.  
When I run that, I get this…

> > cond = c { group\_id === users.map &:id }  
> > SyntaxError: compile error  
> > (irb):3: syntax error, unexpected tAMPER, expecting ‘}’  
> > cond = c { group\_id === users.map &:id }  
> > ^  
> > from (irb):3

But if I take out the &:id thing and just use this…

> > cond = c { group\_id === users.map }

I get what I previously got; the primary key and not the group\_id  
column.

I also updated to the latest svn.

Thank you for your help,  
Mike

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 5, 2007, 1:25am UTC](https://www.ruby-forum.com/t/ez-where-problems/91100/3 "2007-04-05T01:25:26Z")

</div>

Hey Mike-

On Apr 4, 2007, at 9:43 AM, removed\_email\_address@domain.invalid wrote:

> > > cond = Caboose::EZ::Condition.new do  
> > > “updated\_on”=\>“2007-04-02 11:07:00”, “admin”=\>“0”, “username”=\>“bob”,  
> > > SELECT \* FROM results WHERE (group\_id IN (2,5))
> 
> 2,5 are the primary keys of the row ‘bob’. What I want is the  
> ‘group\_id’, which is ‘1,2’.
> 
> If anybody can help, that would be great.
> 
> Thanks in advanced…  
> mike

You seem to have an old version of the plugin. Can I get you to use  
the latest here:

svn checkout svn://rubyforge.org/var/svn/ez-where

The syntax has changed a little bit too. But You can get what you  
want like this:

username = ‘bob’  
users = User.find\_all\_by\_username username

cond = c { group\_id === users.map &:id }

results = Result.find(:all, :conditions =\> cond.to\_sql)

Give that a try once you have the new plugin installed.

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 5, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/ez-where-problems/91100/4 "2007-04-05T17:24:05Z")

</div>

My fault… I figured out what the problem was… If I do this…

```
cond = c { group_id === users.map( &:group_id ) }

```

Everything works. Thank you for your help!!!

Mike
