# Has many... more

**URL:** <https://www.ruby-forum.com/t/has-many-more/140659>\
**Category:** Rails\
**Created:** [June 17, 2008, 8:54am UTC](https://www.ruby-forum.com/t/has-many-more/140659 "2008-06-17T08:54:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![giuseb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@giuseb](https://www.ruby-forum.com/u/giuseb)\
**Post date:** [June 17, 2008, 8:54am UTC](https://www.ruby-forum.com/t/has-many-more/140659/1 "2008-06-17T08:54:04Z")

</div>

Hello there,

a Person has\_many projects, and a Project has\_many tasks.  
Thus, a Person also has many tasks.

Is there a way to write this has\_many in the Person class without using  
:finder\_sql?

Thanks a bunch in advance!  
Giuseppe

---

<div class="post-metadata">

**Author:** ![giuseb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@giuseb](https://www.ruby-forum.com/u/giuseb)\
**Post date:** [June 17, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/has-many-more/140659/2 "2008-06-17T14:12:34Z")

</div>

On Tue, Jun 17, 2008 at 2:54 AM, Giuseppe B. \<  
removed\_email\_address@domain.invalid\> wrote:

> Hello there,
> 
> a Person has\_many projects, and a Project has\_many tasks.  
> Thus, a Person also has many tasks.
> 
> Is there a way to write this has\_many in the Person class without using  
> :finder\_sql?

class Task \< ActiveRecord::Base  
belongs\_to :project  
end

class Project \< ActiveRecord::Base  
belongs\_to :person  
has\_many :tasks  
end

class Person \< ActiveRecord::Base  
has\_many :projects  
has\_many :tasks, :through =\> :projects  
end

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![giuseb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@giuseb](https://www.ruby-forum.com/u/giuseb)\
**Post date:** [June 17, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/has-many-more/140659/3 "2008-06-17T17:16:56Z")

</div>

DUH!  
I had always thought that :through would only apply to a model that  
belongs\_to the other two (like a join table).

I should have tried this before going to the forum.

Thanks Rick,  
Giuseppe

Rick Denatale wrote:

> class Task \< ActiveRecord::Base  
> belongs\_to :project  
> end
> 
> class Project \< ActiveRecord::Base  
> belongs\_to :person  
> has\_many :tasks  
> end
> 
> class Person \< ActiveRecord::Base  
> has\_many :projects  
> has\_many :tasks, :through =\> :projects  
> end
