From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: GNATColl ORM problem (foreign key twins) Date: Wed, 30 Oct 2013 12:43:51 +0000 Organization: A noiseless patient Spider Message-ID: References: <87zjprp1cz.fsf@adaheads.sparre-andersen.dk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="feb3f5761668d64af19c3661aa3d3ca4"; logging-data="31622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186IwjOE69IH5k+SSToE+MNHiP6MbO+b30=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:9Tu7up4gdBmFkSTTA/Uer0/LVbw= sha1:6jJ7ijb9gpN2FtmiiEUGnt3qNNY= X-Original-Bytes: 2375 Xref: number.nntp.dca.giganews.com comp.lang.ada:183756 Date: 2013-10-30T12:43:51+00:00 List-Id: Jacob Sparre Andersen writes: > I want to model a collection of categories and subcategories in a > database like this: > > | TABLE | categories | category | | Item categorisations | > | name | Text | PK | | | > > | TABLE | category_subsets | category_subset | | Item categorisations | > | superset | FK categories(name) | NOT NULL | | | > | subset | FK categories(name) | NOT NULL | | | > > But this fails because GNATColl names the foreign key fields with the > referenced field name instead of with the referencing field name. I think that the problem is that the thing in brackets is not meant to be the PK in the table that is being referenced, it's the name of the reverse relationship. Look for 'revert_name' under [1] (I'm pretty sure this should be 'reverse_name', BTW). So yours would be | TABLE | category_subsets | category_subset | | Item categorisations | | superset | FK categories(parents) | NOT NULL | | | | subset | FK categories(children) | NOT NULL | | | and you get a function Parents that takes a Category and returns (a list of?) Categories (a Category_Manager?). [1] http://docs.adacore.com/gnatcoll-docs/sql.html#database-schema