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