ensure query(X).add_entity(Y) produces the same internal state as query(X, Y)

Issue #1188 resolved
Former user created an issue

A has link to B; then * query(A,B).join(A.linktoB) * query(A).join(A.linktoB).add_entity(B) * query(A).add_entity(B).join(A.linktoB) * query(B,A).join(B.backtoA) * query(B).join(B.backtoA).add_entity(A) * query(B).add_entity(A).join(B.backtoA) should be equivalent?

if B is not to be aliased / not with_polymorphic, all is ok; else, above give different results, some nothing, some decart product coming from having both B and Baliased in FROM

svil / az () svilendobrev _com

Comments (4)

  1. Mike Bayer repo owner

    here's a patch for this one:

    --- lib/sqlalchemy/orm/query.py (revision 5505)
    +++ lib/sqlalchemy/orm/query.py (working copy)
    @@ -113,7 +113,8 @@
                         mapper, selectable, is_aliased_class = _entity_info(entity)
                         if not is_aliased_class and mapper.with_polymorphic:
                             with_polymorphic = mapper._with_polymorphic_mappers
    -                        self.__mapper_loads_polymorphically_with(mapper, sql_util.ColumnAdapter(selectable, mapper._equivalent_columns))
    +                        if mapper.mapped_table not in self._polymorphic_adapters:
    +                            self.__mapper_loads_polymorphically_with(mapper, sql_util.ColumnAdapter(selectable, mapper._equivalent_columns))
                             adapter = None
                         elif is_aliased_class:
                             adapter = sql_util.ColumnAdapter(selectable, mapper._equivalent_columns)
    
  2. Log in to comment