Ternary associations


#1

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)
Belgian Federal Science Policy Office (http://www.belspo.be )
Tel:+32 2 650 5751 Fax: +32 2 650 5124


#2

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


#3

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
To: removed_email_address@domain.invalid
Sent: Wednesday, November 16, 2005 12:21 PM
Subject: Re: [Rails] ternary associations - Checked by AntiVir DEMO
version -


#4

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.


#5

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