# "find\_all\_by\<associated class\>"?

**URL:** <https://www.ruby-forum.com/t/find-all-by-associated-class/124986>\
**Category:** Rails\
**Created:** [January 4, 2008, 11:23am UTC](https://www.ruby-forum.com/t/find-all-by-associated-class/124986 "2008-01-04T11:23:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [January 4, 2008, 11:23am UTC](https://www.ruby-forum.com/t/find-all-by-associated-class/124986/1 "2008-01-04T11:23:55Z")

</div>

If an “Learningobject” belongs to a “Kind”, and a kind has many  
learningobjects, linked in the usual way where a learningobject has a  
kind\_id field, can i set up the method\_missing stuff so that i can say

Learningobject.find\_all\_by\_kind(“some\_value”)

?

In a DB i’m working on, previously each learningobect simply had a  
string to represent their kind. I changed this to reference a new  
“kinds” table, but now i’m having problems with “paginate\_by\_kind”,  
which calls “find\_all\_by\_kind”, creating the problem above. I’ve  
already created get and set methods for kind in learningobject.

thanks! max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [January 4, 2008, 11:35am UTC](https://www.ruby-forum.com/t/find-all-by-associated-class/124986/2 "2008-01-04T11:35:20Z")

</div>

Max W. wrote:

> If an “Learningobject” belongs to a “Kind”, and a kind has many  
> learningobjects, linked in the usual way where a learningobject has a  
> kind\_id field, can i set up the method\_missing stuff so that i can say
> 
> Learningobject.find\_all\_by\_kind(“some\_value”)
> 
> ?
> 
> In a DB i’m working on, previously each learningobect simply had a  
> string to represent their kind. I changed this to reference a new  
> “kinds” table, but now i’m having problems with “paginate\_by\_kind”,  
> which calls “find\_all\_by\_kind”, creating the problem above. I’ve  
> already created get and set methods for kind in learningobject.
> 
> thanks! max

Never mind, i worked it out, it’s pretty obvious really (usually writing  
out these questions makes the answer pop into my head a few minutes  
after posting, sorry!). I can just call  
Learningobject.find\_all\_by\_kind\_id  
instead. doh.

thanks for reading anyway.
