From b99480aac23fdd4e0ef3633703ca5b32ea49805a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 1 Aug 2012 00:08:55 -0400 Subject: - [bug] with_polymorphic() produces JOINs in the correct order and with correct inheriting tables in the case of sending multi-level subclasses in an arbitrary order or with intermediary classes missing. [ticket:1900] --- lib/sqlalchemy/orm/mapper.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/orm/mapper.py') diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 4ff26cc21..0254933c2 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1347,12 +1347,19 @@ class Mapper(_InspectionAttr): if spec == '*': mappers = list(self.self_and_descendants) elif spec: - mappers = [_class_to_mapper(m) for m in util.to_list(spec)] - for m in mappers: + mappers = set() + for m in util.to_list(spec): + m = _class_to_mapper(m) if not m.isa(self): raise sa_exc.InvalidRequestError( "%r does not inherit from %r" % (m, self)) + + if selectable is None: + mappers.update(m.iterate_to_root()) + else: + mappers.add(m) + mappers = [m for m in self.self_and_descendants if m in mappers] else: mappers = [] -- cgit v1.2.1