Re: [SQLObject] Intermediate table in RelatedJoins
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Neil M. <drn...@gm...> - 2009-08-12 11:18:39
|
On Wed, Aug 12, 2009 at 12:36 PM, Miguel Tavares<mig...@gm...> wrote: > Hi Oleg! > > A second intermediate table can be used to state a second many-to-many > relationship and it might make more sense to have it in reverse > order. > > Imagine this scenario: > > class Address(SQLObject): > Address = sqlobject.StringCol () > People = sqlobject.RelatedJoin ('Person') > > class Person(SQLObject): > Name = sqlobject.StringCol () > Addresses = sqlobject.RelatedJoin ('Address') > > So a Person can have several addresses (House, Work, Beach House, etc) > and each Address can be for several Persons (all the member of the > family for example). > > Does this makes any sense? With this example, you'll create an intermediate table which looks something like: id1 : idPerson1 : idAddress1 id2 : idPerson1 : idAddress2 id3 : idPerson2 : idAddress1 id4 : idPerson2 : idAddress3 etc. where idPerson & idAddress are the identifiers for the respective entries in the Person and Address tables [1]. This captures the entire relationship - selecting entries based on the address will give you all the Person records, and selecting on the Person will give you all the address records. I'm not seeing why you think you need multiple intermediate tables? [1] I've swapped the order of the two columns from how sqlobject will actually create the table, but that doesn't really matter. -- Neil Muller drn...@gm... I've got a gmail account. Why haven't I become cool? |