Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0B52763732F for ; Tue, 9 Feb 2010 15:42:03 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 53824-03 for ; Tue, 9 Feb 2010 19:41:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sargon.lncsa.com (mail.lncsa.com [213.215.28.11]) by mail.postgresql.org (Postfix) with ESMTP id 57E9D632EF5 for ; Tue, 9 Feb 2010 15:41:52 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id A5497300DF03 for ; Tue, 9 Feb 2010 20:41:50 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U66V-2m0+NC3 for ; Tue, 9 Feb 2010 20:41:50 +0100 (CET) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id 7C701300E35F for ; Tue, 9 Feb 2010 20:41:50 +0100 (CET) Received: from delos.apartia.fr (delos.apartia.fr [10.0.3.107]) by zenon.apartia.fr (Postfix) with ESMTP id 112475B94212B for ; Tue, 9 Feb 2010 20:41:50 +0100 (CET) Received: by delos.apartia.fr (Postfix, from userid 1000) id 05E18200177BD; Tue, 9 Feb 2010 20:41:49 +0100 (CET) Date: Tue, 9 Feb 2010 20:41:49 +0100 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: Re: 'image' table with relationships to different objects Message-ID: <20100209194149.GA22261@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org References: <20100209074909.GA11838@apartia.fr> <4B714E12.1090207@archonet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4B714E12.1090207@archonet.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.134 tagged_above=-10 required=5 tests=AWL=0.465, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/35 X-Sequence-Number: 33634 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