Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 6713F3405C7 for ; Wed, 22 Feb 2012 07:18:39 -0400 (AST) Received: from iota.marktest.pt ([80.251.174.118] helo=hermes.marktest.pt) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S0ADV-000520-Vv for pgsql-sql@postgresql.org; Wed, 22 Feb 2012 11:18:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by hermes.marktest.pt (Postfix) with ESMTP id 2882F1A815D; Wed, 22 Feb 2012 11:18:24 +0000 (WET) X-Virus-Scanned: amavisd-new at marktest.pt Received: from hermes.marktest.pt ([127.0.0.1]) by localhost (hermes.marktest.pt [127.0.0.1]) (amavisd-new, port 11124) with ESMTP id jF3Gm0YpnUq3; Wed, 22 Feb 2012 11:18:24 +0000 (WET) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by hermes.marktest.pt (Postfix) with ESMTP id 102171A8157; Wed, 22 Feb 2012 11:18:24 +0000 (WET) Message-ID: From: "Oliveiros d'Azevedo Cristina" To: "Gary Stainburn" , References: <201202221035.11963.gary.stainburn@ringways.co.uk> Subject: Re: Another constant in foreign key problem. Date: Wed, 22 Feb 2012 11:18:23 -0000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Pg-Spam-Score: 0.4 (/) X-Archive-Number: 201202/69 X-Sequence-Number: 36362 Hi, Gary, I'm answering by editing your e-mail ______ >I have three tables, > > users - all users of my web site > facilities - facilities available on my web site > facility_levels - access levels per user/facility. > > One of my facilities is a document library (f_id = 22) > For this facility I have the levels > > select * from facility_levels where fl_f_id=22 order by fl_level; > fl_f_id | fl_level | fl_desc > ---------+----------+-------------- > 22 | 1 | Read Only > 22 | 2 | Add Versions > 22 | 3 | Amend > (3 rows) > > > This sets the global access level for the Document Library per user. * It is not clear for me how this sets the global access level per user. Shouldnt the facility_levels table have a u_id field, foreign key from users table? And thus becoming an associative table between users and facilities? > > I now want to add authentication control on a document or folder level. > For > this I need to create a table library_document_user_level > > u_id - user id > ld_id - library document id > fl_level - level > > The foreign key constraint on fl_level needs to check facility_levels for > fl_f_id = 22 as well as fl_level existing. > * I may not be fully understanding your problem, but library_document_user_level shouldn't have a field named fl_f_id, to identify which facility the document/folder belongs to? Had it such a field, you could do something like FOREIGN_KEY (fl_f_id,fl_level) REFERENCES facility_levels (fl_f_id, fl_level) Just my two cents Best, Oliveiros > I've googled this but can't find a suitable solution. Can anyone help > please. > -- > Gary Stainburn > Group I.T. Manager > Ringways Garages > http://www.ringways.co.uk > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql