# Ternary associations

**URL:** <https://www.ruby-forum.com/t/ternary-associations/48056>\
**Category:** Rails\
**Created:** [November 16, 2005, 11:41am UTC](https://www.ruby-forum.com/t/ternary-associations/48056 "2005-11-16T11:41:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jduflost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@jduflost](https://www.ruby-forum.com/u/jduflost)\
**Post date:** [November 16, 2005, 11:41am UTC](https://www.ruby-forum.com/t/ternary-associations/48056/1 "2005-11-16T11:41:50Z")

</div>

Hello all,

Does anybody know how I can handle ternary associations with rails ?  
Could  
you give me an example ?

Thank you.

Johan

Johan Duflost  
Analyst Programmer  
Belgian Biodiversity Platform ( [http://www.biodiversity.be](http://www.biodiversity.be))  
Belgian Federal Science Policy Office ([http://www.belspo.be](http://www.belspo.be) )  
Tel:+32 2 650 5751 Fax: +32 2 650 5124

---

<div class="post-metadata">

**Author:** ![jduflost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@jduflost](https://www.ruby-forum.com/u/jduflost)\
**Post date:** [November 16, 2005, 1:21pm UTC](https://www.ruby-forum.com/t/ternary-associations/48056/2 "2005-11-16T13:21:20Z")

</div>

On 16.11.2005, at 12.38, johan duflost wrote:

> Hello all,
> 
> Does anybody know how I can handle ternary associations with  
> rails ? Could you give me an example ?

Hi Johan,

Give the “association” a class of its own. I’m running out of good  
examples (this one’s a bit on the cynical side) but here goes anyway:

Bride has\_many :weddings  
Groom has\_many :weddings  
Church has\_many :weddings

Wedding  
belongs\_to :bride  
belongs\_to :groom  
belongs\_to :church

Here the wedding is the “association”. But as it’s also a class, it  
is a lot more flexible than a simple association. And no, there is no  
way to build a ternary (or any other n-ary, n\>2) “dummy” relationship  
Ã¡ la has\_and\_belongs\_to\_many.

//jarkko

---

<div class="post-metadata">

**Author:** ![jduflost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@jduflost](https://www.ruby-forum.com/u/jduflost)\
**Post date:** [November 16, 2005, 1:24pm UTC](https://www.ruby-forum.com/t/ternary-associations/48056/3 "2005-11-16T13:24:23Z")

</div>

It’s a join table that links three tables. Often a join table links only  
two  
and all examples are based on this assumption.

model1\_id model2\_id model3\_id additional\_attribute1  
additional\_attribute2 …

Johan

----- Original Message -----  
From: “Jeroen H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Wednesday, November 16, 2005 12:21 PM  
Subject: Re: [Rails] ternary associations - Checked by AntiVir DEMO  
version -

---

<div class="post-metadata">

**Author:** ![jduflost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@jduflost](https://www.ruby-forum.com/u/jduflost)\
**Post date:** [November 16, 2005, 1:27pm UTC](https://www.ruby-forum.com/t/ternary-associations/48056/4 "2005-11-16T13:27:24Z")

</div>

a ternary association is a 3-way association or relationship between  
objects, as opposed to a binary (2-way) which you see in Rails, or  
quaternary (4-way), and so on…

now, whether Rails does 3-ary i have no idea. i haven’t seen any  
documentation on it, so i would assume no, however, don’t take that as  
the  
definitive answer.

---

<div class="post-metadata">

**Author:** ![jduflost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@jduflost](https://www.ruby-forum.com/u/jduflost)\
**Post date:** [November 16, 2005, 12:24pm UTC](https://www.ruby-forum.com/t/ternary-associations/48056/5 "2005-11-16T12:24:00Z")

</div>

johan duflost wrote:

> Hello all,
> 
> Does anybody know how I can handle ternary associations with rails ?  
> Could you give me an example ?

What’s a ternary association?

Jeroen
