join table design question

From: Peter Michaux <petermichaux(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: join table design question
Date: 2006-01-14 23:51:44
Message-ID: 3cbaf1c80601141551r659e6857mefaa44e83499862c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have tried two db designs and both can work but I wonder which one
the db 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 and images have a many-to-many relationship and
products and images have a many-to-many relationship. (It may be that
many other tables can have many-to-many relationship with 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 each would require a class in my ORM.

categories_images
- category_id
- image_id

images_products
- product_id
- image_id

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

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 has only one join table and class. It is a little more
complicated and I don't know how it fits
into the normalization stuff.

How do I choose?

Thanks,
Peter

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Paulsen 2006-01-15 00:12:31 Fwd: Re: sort character data in arbitrary order?
Previous Message Zlatko Matić 2006-01-14 23:42:44 visual query builder for Postgres?