# Problems with find

**URL:** <https://www.ruby-forum.com/t/problems-with-find/120788>\
**Category:** Rails\
**Created:** [November 20, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/problems-with-find/120788 "2007-11-20T17:24:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmunoz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dec6dc/32.png) [@rmunoz](https://www.ruby-forum.com/u/rmunoz)\
**Post date:** [November 20, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/problems-with-find/120788/1 "2007-11-20T17:24:31Z")

</div>

Hi guys,  
I’m with a problem trying to use find\_\*  
check example code here: [http://rafb.net/p/1sZSvM83.html](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

> **[Quero ser Ágil](https://queroseragil.wordpress.com)**
>
> Idéias e experiências de um desenvolvedor em busca da Agilidade

---

<div class="post-metadata">

**Author:** ![rmunoz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dec6dc/32.png) [@rmunoz](https://www.ruby-forum.com/u/rmunoz)\
**Post date:** [November 20, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/problems-with-find/120788/2 "2007-11-20T17:51:55Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![rmunoz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dec6dc/32.png) [@rmunoz](https://www.ruby-forum.com/u/rmunoz)\
**Post date:** [November 20, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/problems-with-find/120788/3 "2007-11-20T18:07:17Z")

</div>

Hi Thorsten,

On Nov 20, 2007 1:51 PM, Thorsten M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

> **[Quero ser Ágil](https://queroseragil.wordpress.com)**
>
> Idéias e experiências de um desenvolvedor em busca da Agilidade
