Hi!
I’m having another small problem. I run a small query to get all
the group_id’s that are associated with a user. I then take that and
run it in another query in order to display the relevant data/group ID
the user belongs in. But when I do this, sometimes it returns an
error because there’s ‘nomethod’ in array, and other times it returns
nothing. For example, this is my code…
def list
username = ‘bob’
resUser = User.find(:all, :conditions => [“username = :name”,
{:name => username}], :select => “group_id”)
@result_pages, @results = paginate :results, :per_page =>
10, :conditions => [“group_id IN (?)”, resUser]
end
In the logs, it does the first query, but for the second, it shows
‘null’.
SQL (0.000314) SELECT count(*) AS count_all FROM results WHERE
(group_id IN (NULL))
Now if I change some of the code to look like this…
username = 'bob'
resUser = User.find(:all, :conditions => ["username = :name",
{:name => username}])
@result_pages, @results = paginate :results, :per_page =>
10, :conditions => [“group_id IN (?)”, resUser.group_id]
It flashes an NoMethodError exception with…
undefined method `group_id’ for #Array:0x352ca94
To my knowledge, there were some tickets opened on this but it looks
like it has been fixed. One of them is here.
http://dev.rubyonrails.org/ticket/6150
http://dev.rubyonrails.org/ticket/2887
But I’m still having problems trying to get this to work. If anybody
can help, that would be great.
Thanks in advanced…