Forum: Ruby on Rails Polymorphic many to many linking

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Just S. (Guest)
on 2005-12-31 10:14
(Received via mailing list)

I'm trying to create a model where a few objects can all be linked to
each other through a central linking table. Table structure is like

-- model class Computer
create table computers (
  id serial,
  description varchar

-- model Class user
create table users (
  id serial,
  name varchar

-- model class Desk
create table desks (
  id serial,
  location varchar

-- The linking table
create table linkings (
  source_id int,
  source_type varchar,
  link_id int,
  link_type varchar,
  created_at timestamp,
  comments varchar

I want to use has_many / belongs_to or some other association to be
able to have any number of objects from different types linked to each
object. I don't want to create multiple linkings tables for that, as
the more objects I have the increase in number of tables will be huge.

Any way to cleanly solve this?

I tried also with the latest edge with the new polymorphic relations,
but still can't get it to do work this way.


This topic is locked and can not be replied to.