Re: 'image' table with relationships to different objects

From: Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: 'image' table with relationships to different objects
Date: 2010-02-09 19:41:49
Message-ID: 20100209194149.GA22261@apartia.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Feb 09, 2010 at 11:59:14AM +0000, Richard Huxton wrote:
> On 09/02/10 07:49, Louis-David Mitterrand wrote:
> >Hello,
> >
> >In my database I have different object types (person, location, event,
> >etc.) all of which can have several images attached.
> >
> >What is the best way to manage a single 'image' table with relationships
> >to (potentially) many different object types while keeping referrential
> >integrity (foreign keys)?
>
> The "clean" way to do this would be with a number of joining tables:
>
> images (img_id, file_name, title ...)
> persons (psn_id, first_name, last_name, ...)
> locations (loc_id, loc_name, lat, lon, ...)
> events (evt_id, evt_name, starts_on, ends_on, ...)
>
> person_images (psn_id, img_id)
> location_images (loc_id, img_id)
> event_images (evt_id, img_id)

Thank you Richard, this looks like the best solution. And the view is
handy.

--
http://www.critikart.net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andrea Visinoni 2010-02-10 16:29:18 plpgsql loop question
Previous Message Rob Sargent 2010-02-09 15:01:35 Re: 'image' table with relationships to different objects