# Compact db design a bad idea?

**URL:** <https://www.ruby-forum.com/t/compact-db-design-a-bad-idea/61478>\
**Category:** Rails\
**Created:** [January 14, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/compact-db-design-a-bad-idea/61478 "2006-01-14T23:22:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [January 14, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/compact-db-design-a-bad-idea/61478/1 "2006-01-14T23:22:25Z")

</div>

Hi,

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  
tables

categories

- id
- name

products

- id
- name

images

- 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)

categories\_images

- category\_id
- image\_id

images\_products

- product\_id  
\_ image\_id

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

image\_joins

- 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?

Thanks,  
Peter
