Problems with find

Hi guys,
I’m with a problem trying to use find_*
check example code here: http://rafb.net/p/1sZSvM83.html

So, the problem is, if I try to do
Task.find_all_by_project_id(u.projects) it doesnt work, but this
Task.find_all_by_project_id(u.projects.collect{|p| p.id}) works.

Any help?

Rafael Mueller

Task.find_all_by_project_id(u.projects) it doesnt work, but this

projects contains an array with hashes which looks like:
[{:id => 1, :name => ‘me’}, {:id => 2, :name => ‘you’}]

rails can’t know which key in the hash to use (ok, it could be
nice and default to id…)

Task.find_all_by_project_id(u.projects.collect{|p| p.id}) works.

this collects all projects ids in an array like
[1, 2]

which rails can handle

Hi Thorsten,

On Nov 20, 2007 1:51 PM, Thorsten M.
[email protected]
wrote:

Task.find_all_by_project_id(u.projects) it doesnt work, but this

projects contains an array with hashes which looks like:
[{:id => 1, :name => ‘me’}, {:id => 2, :name => ‘you’}]

rails can’t know which key in the hash to use (ok, it could be
nice and default to id…)

Actually, i think rails know wich one is the key, because the generated
query is:
“SELECT * FROM tasks WHERE (tasks.project_id = 3,4)”
Rails got the right key, but he can’t identify thats an array, i think.

Regards,

Rafael Mueller