# Modeling question

**URL:** <https://discuss.rubyonrails.org/t/modeling-question/4585>\
**Category:** rubyonrails-talk\
**Created:** [November 15, 2006, 10:34pm UTC](https://discuss.rubyonrails.org/t/modeling-question/4585 "2006-11-15T22:34:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christos\_Zisopoulos2](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Christos\_Zisopoulos2](https://discuss.rubyonrails.org/u/Christos_Zisopoulos2)\
**Post date:** [November 15, 2006, 10:34pm UTC](https://discuss.rubyonrails.org/t/modeling-question/4585/1 "2006-11-15T22:34:51Z")

</div>

Sam, I am assuming you have the following...

class Salesperson \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;has\_many :customers &nbsp;&nbsp;&nbsp;&nbsp;has\_many :purchased\_products, :through =\> :customers end

class Customer \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :salesperson &nbsp;&nbsp;&nbsp;&nbsp;has\_many :purchased\_products end

class PurchasedProduct \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :customer end

...and also:

table "purchased\_products" with "customer\_id" table "customers" with "salesperson\_id"

And what you do is:

Salesperson.find(:first).purchased\_products

This works as advertised. I've just tried id. Do you get an error in  
the log?

Or did you just not get the results you expected? I ask, because your model is flawed as it only allows each Product to  
be purchased by ONE customer only. Same goes for Customers and  
Salespeople. Each Customer belongs to only ONE Salesperson.

Did you mean to us has\_and\_belongs\_to\_many in these occasions? Or  
even a "Customer has\_many :products, :through =\> :purchases" and  
"Salesperson has\_many :customers, :through =\> :sales" and utilise the  
two join models Purchases, Sales?

-christos
