I am looking for one table to have a one-to-many relationship with many other tables. For example, I have a table 'collections', and I have other tables 'photos', 'videos', 'mp3s' etc.
Is there a way to get this using rails?
This is kind of the opposite of a polymorphic relationship: 'With polymorphic associations, a model can belong to more than one other model, on a single association'
Here, I want one model to have a one-to-many relationship with records from many other tables.
I know I could create the join table myself with three fields: the collection_id, the name of the table and the record id inside it, and write SQL to retrieve all the records that belong to a collection.But that is cumbersome.
Another way might be to put has_many entries for each of photos, videos, mp3s, in the collections table, and belongs_to :collection entries in each of photos, videos, mp3s, and create appropriate references in the collections table. If later I want to add some other type, say dvds, I have to modify the collections table. I guess this is not too bad, if no easier method exists.
Django (Python) has a notion of GenericRelation and that is exactly what I am looking for.
Thanks Nara