ez_where problems

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

Hey Mike-

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

  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 Zygmuntowicz-- Lead Rails Evangelist -- ez@engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273)

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

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