Forum: Ruby on Rails Compact db design a bad idea?

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.
Peter M. (Guest)
on 2006-01-15 00:22
(Received via mailing list)

I have tried two db designs and both can work but I wonder which one
the Rails Gurus would go with. This is a general db design question
that has cropped up in a few situation. Here is the example I've been
working on.

In an online store, categories has_and_belongs_to_many images and
products has_and_belongs_to_many images. The db has the basic three

- id
- name

- id
- name

- id
- filename

What I can't decide on is how to do the join tables.

Option 1 - would have many join tables and require many join models.
(The join models are to use the position field for acts_as_list to
order the images)

- category_id
- image_id

- product_id
_ image_id

Option 2 - have a one generic join table and only one join model

- owner_class
- owner_id
- image_id

In option 2 a record could be (Category, 2, 3) or (Product, 4, 1)


Option 1 seems simpler but could lead to some repetitive code (at
least in the data base definition).

Option 2 is a little more complicated and I don't know how it fits
into the normalization stuff.

How do I choose?

This topic is locked and can not be replied to.