Polymorphic many to many linking


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.