From: Mike Bayer Date: Mon, 27 Mar 2006 02:58:20 +0000 (+0000) Subject: tweak to mapper to allow inheritance on the same table. X-Git-Tag: rel_0_1_5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19e9af44c0fcf2ac36c8957c0d23b691e111e359;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git tweak to mapper to allow inheritance on the same table. --- diff --git a/CHANGES b/CHANGES index a996bd5647..e454a4e65a 100644 --- a/CHANGES +++ b/CHANGES @@ -31,6 +31,8 @@ commit concept of relations on a mapper being made towards the "local" table for that mapper, not the tables it inherits. allows more complex compositional patterns to work with lazy/eager loading. +- added support for mappers to inherit from others based on the same table, +just specify the same table as that of both parent/child mapper. - some minor speed improvements to the attributes system with regards to instantiating and populating new objects. - fixed MySQL binary unit test diff --git a/lib/sqlalchemy/mapping/mapper.py b/lib/sqlalchemy/mapping/mapper.py index ed07983e44..a0de86df4f 100644 --- a/lib/sqlalchemy/mapping/mapper.py +++ b/lib/sqlalchemy/mapping/mapper.py @@ -71,22 +71,24 @@ class Mapper(object): if inherits is not None: self.primarytable = inherits.primarytable # inherit_condition is optional. - if inherit_condition is None: - # figure out inherit condition from our table to the immediate table - # of the inherited mapper, not its full table which could pull in other - # stuff we dont want (allows test/inheritance.InheritTest4 to pass) - inherit_condition = sql.join(inherits.noninherited_table, table).onclause - self.table = sql.join(inherits.table, table, inherit_condition) - #print "inherit condition", str(self.table.onclause) - - # generate sync rules. similarly to creating the on clause, specify a - # stricter set of tables to create "sync rules" by,based on the immediate - # inherited table, rather than all inherited tables - self._synchronizer = sync.ClauseSynchronizer(self, self, sync.ONETOMANY) - self._synchronizer.compile(self.table.onclause, util.HashSet([inherits.noninherited_table]), TableFinder(table)) - # the old rule - #self._synchronizer.compile(self.table.onclause, inherits.tables, TableFinder(table)) + if not table is inherits.noninherited_table: + if inherit_condition is None: + # figure out inherit condition from our table to the immediate table + # of the inherited mapper, not its full table which could pull in other + # stuff we dont want (allows test/inheritance.InheritTest4 to pass) + inherit_condition = sql.join(inherits.noninherited_table, table).onclause + self.table = sql.join(inherits.table, table, inherit_condition) + #print "inherit condition", str(self.table.onclause) + # generate sync rules. similarly to creating the on clause, specify a + # stricter set of tables to create "sync rules" by,based on the immediate + # inherited table, rather than all inherited tables + self._synchronizer = sync.ClauseSynchronizer(self, self, sync.ONETOMANY) + self._synchronizer.compile(self.table.onclause, util.HashSet([inherits.noninherited_table]), TableFinder(table)) + # the old rule + #self._synchronizer.compile(self.table.onclause, inherits.tables, TableFinder(table)) + else: + self._synchronizer = None self.inherits = inherits self.noninherited_table = table else: