Forum: Ruby on Rails N:M:K Relationships

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Roland M. (Guest)
on 2006-04-18 23:21
Hello there,

I was wondering whether rails 1.1.1 supports N:M:K relationships that is
having a pivot table with three columns which are primary keys:

  say, (apple_id, orange_id, lemon_id)

It would be so great if Rails could be able to have id-s which as
n-tuples.

Thanks,

Roland
Gregory S. (Guest)
on 2006-04-18 23:37
(Received via mailing list)
On Tue, Apr 18, 2006 at 09:21:51PM +0200, Roland M. wrote:
} Hello there,
}
} I was wondering whether rails 1.1.1 supports N:M:K relationships that
is
} having a pivot table with three columns which are primary keys:
}
}   say, (apple_id, orange_id, lemon_id)
}
} It would be so great if Rails could be able to have id-s which as
} n-tuples.

I wouldn't expect it to ever support n-way relationships directly. You
can,
however, do this:

AOL
belongs_to :apple
belongs_to :orange
belongs_to :lemon

Apple
has_many :aols

Orange
has_many :aols

Lemon
has_many :aols

Also, I believe you can use has_many :through to get to the other
objects
more directly.

} Thanks,
} Roland
--Greg
This topic is locked and can not be replied to.