-----BEGIN PGP SIGNED MESSAGE-----
Just a quick question and sorry I couldn't find this out myself (I'm not
very good in RDMS slang, so maybe it's even documented but I didn't got
it). How can I have a One-to-Many relationship, where the "Many" side is
fetched from multiple tables? addr = MultipleJoin(Addr) gives me all
rows from a table 'addr', but what if I wanted all rows from two tables,
lets say 'addr1' 'addr2'?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
From: Carlos Ribeiro <carribeiro@gm...> - 2005-02-04 20:07:26
On Mon, 07 Feb 2005 13:35:57 +0100, pkoelle <pkoelle@...> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> Carlos Ribeiro wrote:
> | Paul,
> | I'm trying to understand what do you want to do. From a totally
> | outsider point of view, it does not make much sense... unless you have
> | two tables that share a lot of information in common, or at least,
> | have a lot of structural overlap. Sounds like stuff to be handled via
> | inheritance (in the DB-sense - there were lots of discussion on it
> | over the past few weeks). I believe that the only way someone can help
> | you is by having some understanding of your db schema.
> Thanks Carlos, the discussion went off-list, I'll restate the problem
> just for the record and because I think there is a conceptual issue
> somewhere others might find interesting. CC to the list if you feel so.
It was a mistake, I did a reply instead of a reply all. Sorry. It was
intended to go to the list too.
> ~ descendants = MultipleJoin('Intermediate')
> ~ parent = ForeignKey('Root')
> ~ leaves = MultipleJoin('Leaves1')
> ~ _table = 'intermediate'
> ~ leaves = MultipleJoin('Leaves2')
> ~ _table = 'intermediate'
> ~ branch = ForeignKey('Branch1')
> ~ branch = ForeignKey('Branch2')
> for some reason I thought Branch1.select() would still get back only
> instances of itself and not all rows from the 'intermediate' table. As
> this is not the case a 'leaves' instance's branch attribute will not
> necessarily point to its parent branch but to whatever comes first in
> the 'intermediate' table.
> My initial thought was to use the _table thing to model the hierarchy
> i.e. a "three elements chain" with two one-to-many relationships
> Root<->Branch and Branch<->Leave but apparently this doesn't work.
I'm no SQL guru either, but I notice two things about your sample:
1) There are several advanced techniques to model tree-like structures
using only flat tables and a strict relational model. I sincerely
forgot the relevant links, but I'm sure you can find them on Google. I
believe that some of these techniques may be better than your current
approach, but I may be wrong..
2) Roughly speaking, your current schema tries to model inheritance
with SQLObject. There was a discussion about it recently, you can find
it in the archives. Check for all messages concerning the 'inheritance
branch', specially the recent thread; please note the messages from
Ian and Oleg. The inheritance branch is available through SVN. It uses
a different attribute (_inheritable, I think) to create the
parent-child relationship. I don't use it, so there's little that I
can add at this point, but it seems that it's exactly what you're
Consultoria em Projetos