# Has\_many with :through question

**URL:** <https://www.ruby-forum.com/t/has-many-with-through-question/129137>\
**Category:** Rails\
**Created:** [February 14, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/has-many-with-through-question/129137 "2008-02-14T19:06:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nahabed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@nahabed](https://www.ruby-forum.com/u/nahabed)\
**Post date:** [February 14, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/has-many-with-through-question/129137/1 "2008-02-14T19:06:35Z")

</div>

This is my first independent RoR project after working with recipes  
from some cool books that I’ve been reading…

Background: I’m building an app that could potentially useful to  
college students. The idea is that between semesters, students at a  
given campus would list textbooks that they have and textbooks that  
they need and the app would match them up (if I have what you want and  
you have what I need, its a match).

So, here are the models I’ve defined so far: Book, User, WantedOffer  
and NeedOffer. A book that is offered will have an additional  
attribute, such as, “condition” (new, used, like new, etc).

Class User \< ActiveRecord::Base  
has\_many wanted\_offers  
has\_many have\_offers  
has\_many books :through =\> wanted\_offers, :have\_offers  
end

Class Book \< ActiveRecord::Base  
has\_many wanted\_offers  
has\_many have\_offers  
has\_many users :through =\> wanted\_offers, :have\_offers  
end

Class HaveOffer \< ActiveRecord::Base  
belongs\_to :book  
belongs\_to :user  
end

Class WantedOffer \< ActiveRecord::Base  
belongs\_to :book  
belongs\_to :user  
end

I don’t know if “:through =\> wanted\_offers, :have\_offers” is a valid  
call (I’m looking into it) but at least now, it makes the model  
relationships work in my mind 🙂 I can get to users from books via  
have\_offers and wanted\_offers and visa versa.

It also looks like I need a :dependent =\> :destroy calls somewhere  
since WantedOffer and HaveOffer don’t make sense without a Book. I’m  
not sure where to put this just yet…

Thanks in advance for the help…
