should not "leak" their inner FROM objects out
into the enclosing query.
+ - Improved the behavior of query.join()
+ when joining to joined-table inheritance
+ subclasses, using explicit join criteria
+ (i.e. not on a relation).
+
- Fixed @on_reconsitute hook for subclasses
which inherit from a base class.
[ticket:1129]
if not clause:
raise sa_exc.InvalidRequestError("Could not find a FROM clause to join from")
- bogus, right_selectable, is_aliased_class = _entity_info(right_entity)
+ mp, right_selectable, is_aliased_class = _entity_info(right_entity)
+
+ if not right_mapper and mp:
+ right_mapper = mp
if right_mapper and not is_aliased_class:
if right_entity is right_selectable:
right_entity = aliased(right_mapper)
alias_criterion = True
aliased_entity = True
-
+
elif prop:
if prop.table in self.__currenttables:
if prop.secondary is not None and prop.secondary not in self.__currenttables:
right_entity = prop.mapper
+ if alias_criterion:
+ right_adapter = ORMAdapter(right_entity,
+ equivalents=right_mapper._equivalent_columns, chain_to=self._filter_aliases)
+
+ if isinstance(onclause, sql.ClauseElement):
+ onclause = right_adapter.traverse(onclause)
+
if prop:
onclause = prop
clause = orm_join(clause, right_entity, onclause, isouter=outerjoin)
if alias_criterion:
- self._filter_aliases = ORMAdapter(right_entity,
- equivalents=right_mapper._equivalent_columns, chain_to=self._filter_aliases)
+ self._filter_aliases = right_adapter
if aliased_entity:
self.__mapper_loads_polymorphically_with(right_mapper, ORMAdapter(right_entity, equivalents=right_mapper._equivalent_columns))
join('paperwork', from_joinpoint=True, aliased=aliased).filter(Paperwork.description.like('%#%')).all(),
[c1, c2]
)
+ def test_explicit_polymorphic_join(self):
+ sess = create_session()
+
+ # join from Company to Engineer; join condition formulated by
+ # ORMJoin using regular table foreign key connections. Engineer
+ # is expressed as "(select * people join engineers) as anon_1"
+ # so the join is contained.
+ self.assertEquals(
+ sess.query(Company).join(Engineer).filter(Engineer.engineer_name=='vlad').one(),
+ c2
+ )
+
+ # same, using explicit join condition. Query.join() must adapt the on clause
+ # here to match the subquery wrapped around "people join engineers".
+ self.assertEquals(
+ sess.query(Company).join((Engineer, Company.company_id==Engineer.company_id)).filter(Engineer.engineer_name=='vlad').one(),
+ c2
+ )
+
def test_filter_on_baseclass(self):
sess = create_session()