# Multiple has\_one to same table

**URL:** <https://www.ruby-forum.com/t/multiple-has-one-to-same-table/190456>\
**Category:** Rails\
**Created:** [June 20, 2010, 9:30pm UTC](https://www.ruby-forum.com/t/multiple-has-one-to-same-table/190456 "2010-06-20T21:30:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkmdnielsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac91a4/32.png) [@dkmdnielsen](https://www.ruby-forum.com/u/dkmdnielsen)\
**Post date:** [June 20, 2010, 9:30pm UTC](https://www.ruby-forum.com/t/multiple-has-one-to-same-table/190456/1 "2010-06-20T21:30:19Z")

</div>

Your input/experience appreciated. I have noticed multiple  
discussions regarding husband and wife. But none really end in a  
“this is a the best way to handle things.” Here is my situation. I’m  
recording information on couples – husband and wife, one of each. If  
the two are no longer married, the couple will evaporate. If either  
person is deleted, then couple will evaporate. I originally thought  
of having all individuals in one table, persons, and then creating  
couple with alink to each person.

# == Schema Information

# Schema version: 20100620123354

# 

# Table name: couples

# 

# id :integer not null, primary key

# active :boolean

# husband\_id :integer # reference to persons table

# wife\_id :integer # reference to persons table

I was then thinking:

belongs\_to :husband,:class\_name=\>“Person”,:foreign\_key=\>“husband\_id”  
belongs\_to :wife,:class\_name=\>“Person”,:foreign\_key=\>“wife\_id”

and then having classes “Husband \< Person” and “Wife \< Person”. Is  
this feasible?

I am so torn I don’t know what step to take next. I’m early in  
development so I can do anything. But what I want to do is what is  
best.

Do I stick with a couples table and one persons table?

Do I create separate tables for husbands and wives? If I do this, can  
I create one Person class and Husband & Wife models inheriting  
Person…that way the two tables are created and migrated  
separately?

You input is really appreciated.  
dvn

---

<div class="post-metadata">

**Author:** ![dkmdnielsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac91a4/32.png) [@dkmdnielsen](https://www.ruby-forum.com/u/dkmdnielsen)\
**Post date:** [June 20, 2010, 10:12pm UTC](https://www.ruby-forum.com/t/multiple-has-one-to-same-table/190456/2 "2010-06-20T22:12:28Z")

</div>

On 20 June 2010 20:05, dkmdnielsen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Your input/experience appreciated. I have noticed multiple  
> discussions regarding husband and wife. But none really end in a  
> “this is a the best way to handle things.”

> **[Gay marriage: the database engineering perspective @ Things Of Interest](https://qntm.org/gay)**
>
> Update, 2017-09-25
> 
> Hi! This essay is undergoing a long-overdue rewrite. In the meantime, consider my 2015 follow-up essay, Obergefell v. Hodges: the database engineering perspective....

Of course, you can stop at level 7 or 8 if it suits you.

---

<div class="post-metadata">

**Author:** ![dkmdnielsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac91a4/32.png) [@dkmdnielsen](https://www.ruby-forum.com/u/dkmdnielsen)\
**Post date:** [June 21, 2010, 5:00pm UTC](https://www.ruby-forum.com/t/multiple-has-one-to-same-table/190456/3 "2010-06-21T17:00:56Z")

</div>

Outside of the fact that there is _really_ excellent information in  
what your link provides, did it have to be so politically charged???

I can at least feel good that I am already at level seven, and some  
semantic changes puts me at eight. I would say stopping at eleven  
works for me (no sex or gender on table), but having gives us a bit of  
a heads up when talking with prospective couples on the phone.  
Knowing Terry or Sam or Francis is a woman gives us a little more  
information.

So is the couple/partnership a child of the person table? Are  
partners 1 & 2 a belongs\_to to Person? Do I try to do a habtm on  
person’s itself using a spouse id?

I’m pretty green on setting up the syntax of all this. Not to mention  
figuring out the database constraints on the table itself.

dvn

---

<div class="post-metadata">

**Author:** ![dkmdnielsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac91a4/32.png) [@dkmdnielsen](https://www.ruby-forum.com/u/dkmdnielsen)\
**Post date:** [June 21, 2010, 5:10pm UTC](https://www.ruby-forum.com/t/multiple-has-one-to-same-table/190456/4 "2010-06-21T17:10:19Z")

</div>

You provided this link elsewhere. This one, too, is excellent for  
setting up the syntax.

> **[rails.info](http://guides.rails.info/association_basics.html#self-joins)**
>
> Ruby on Rails,Rails Tutorial,Ruby Basics,Rails 4,Bar Rails,Rail

Have a good one!
