From 88f42cf1f4baa9818dfb014ac4e162ce345a4459 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 27 Jan 2008 02:21:23 +0000 Subject: - Fixed bug in polymorphic inheritance where incorrect exception is raised when base polymorphic_on column does not correspond to any columns within the local selectable of an inheriting mapper more than one level deep --- lib/sqlalchemy/orm/mapper.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index d9dc70a58..959cf274c 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -352,9 +352,14 @@ class Mapper(object): if self.polymorphic_identity is not None: self.inherits.polymorphic_map[self.polymorphic_identity] = self if self.polymorphic_on is None: - if self.inherits.polymorphic_on is not None: - self.polymorphic_on = self.mapped_table.corresponding_column(self.inherits.polymorphic_on) + for mapper in self.iterate_to_root(): + # try to set up polymorphic on using correesponding_column(); else leave + # as None + if mapper.polymorphic_on: + self.polymorphic_on = self.mapped_table.corresponding_column(mapper.polymorphic_on) + break else: + # TODO: this exception not covered raise exceptions.ArgumentError("Mapper '%s' specifies a polymorphic_identity of '%s', but no mapper in it's hierarchy specifies the 'polymorphic_on' column argument" % (str(self), self.polymorphic_identity)) if self.polymorphic_identity is not None and not self.concrete: -- cgit v1.2.1