1. idank
  2. sqlalchemy


Mike Bayer  committed 079a66d

filter() criterion takes mapper equivalent_columns into account when it adapts to select_table. more to come in [ticket:917] .

  • Participants
  • Parent commits 8d0319b
  • Branches default

Comments (0)

Files changed (2)

File lib/sqlalchemy/orm/query.py

View file
         # be adapted to be relative to the user-supplied selectable.
         adapt_criterion = self.table not in self._get_joinable_tables()
+        # adapt for poylmorphic mapper
+        # TODO: generalize the polymorphic mapper adaption to that of the select_from() adaption
         if not adapt_criterion and whereclause is not None and (self.mapper is not self.select_mapper):
-            whereclause = sql_util.ClauseAdapter(from_obj).traverse(whereclause)
+            whereclause = sql_util.ClauseAdapter(from_obj, equivalents=self.select_mapper._get_equivalent_columns()).traverse(whereclause)
         # TODO: mappers added via add_entity(), adapt their queries also, 
         # if those mappers are polymorphic

File test/orm/inheritance/polymorph.py

View file
         assert getattr(dilbert, person_attribute_name) == 'dilbert'
+        dilbert = session.query(Person).filter(Person.person_id==dilbert.person_id).one()
+        assert getattr(dilbert, person_attribute_name) == 'dilbert'
+        session.clear()
         id = c.company_id
         def go():
             c = session.query(Company).get(id)