# ActiveRecord model design help

**URL:** <https://discuss.rubyonrails.org/t/activerecord-model-design-help/49160>\
**Category:** rubyonrails-talk\
**Created:** [February 6, 2010, 10:13am UTC](https://discuss.rubyonrails.org/t/activerecord-model-design-help/49160 "2010-02-06T10:13:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin1](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Erwin1](https://discuss.rubyonrails.org/u/Erwin1)\
**Post date:** [February 6, 2010, 10:13am UTC](https://discuss.rubyonrails.org/t/activerecord-model-design-help/49160/1 "2010-02-06T10:13:36Z")

</div>

I need some help on the following model design :

User model (user.rb) class User \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;has\_many :analyses, :dependent =\> :destroy

Analysis model (analysis.rb) class Analysis \< ActiveRecord::Base &nbsp;&nbsp;belongs\_to :instructor, :class\_name =\> "User", :foreign\_key =\> :instructor\_id &nbsp;&nbsp;belongs\_to :member, :class\_name =\> "User", :foreign\_key =\> :member\_id

creating an analysis works Analysis.create(:instructor\_id =\> 1, :member\_id =\> 2, :status =\> "pending") I can get : Analysis.first.instructor Analysis.first.member

BUT User.find(1).analyses raise an error : ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'analyses.user\_id' is there any way to handle this design ?

thanks a lot for your help

(btw I use the inflection plural analysis -\> analyses)

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 6, 2010, 10:47pm UTC](https://discuss.rubyonrails.org/t/activerecord-model-design-help/49160/2 "2010-02-06T22:47:32Z")

</div>

To make that work you might have to do this:

class User \< ActiveRecord::Base &nbsp;&nbsp;has\_many :instructor\_analyses, :foreign\_key =\> :instructor\_id, :dependent =\> destroy &nbsp;&nbsp;has\_many :member\_analyses, :foreign\_key =\> :member\_id, :dependent =\> destroy

&nbsp;&nbsp;def analyses &nbsp;&nbsp;&nbsp;&nbsp;instructor\_analyses + member\_analyses &nbsp;&nbsp;end end
