Skip to content

inappropriate setting of polymorphic aliasing for a filter-level alias #2234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sqlalchemy-bot opened this issue Jul 27, 2011 · 2 comments
Closed
Labels
bug Something isn't working orm
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Michael Bayer (@zzzeek)

which you can see in a self-referential joined inh join from class to itself.

from sqlalchemy import *
from sqlalchemy.orm import *

class A(object):
    pass

class B(A):
    pass

m = MetaData()
a_table = Table('a', m,
    Column('id', Integer, primary_key=True),
)

b_table = Table('b', m,
    Column('id', Integer, ForeignKey('a.id'), primary_key=True),
    Column('b_id', Integer, ForeignKey('b.id')),
)

mapper(A, a_table, )
mapper(B ,b_table, inherits=A,
              properties={
                'bs':relationship(B, primaryjoin=b_table.c.id==b_table.c.b_id)
            })

s = Session()

print s.query(B).join(B.bs, aliased=True).statement

print s.query(B.id).join(B.bs, aliased=True).statement

and here's a patch !

diff -r 5c7cc274250c54430d9dceb05ad2a4a33e2378d7 lib/sqlalchemy/orm/query.py
--- a/lib/sqlalchemy/orm/query.py	Sun Jul 24 20:41:42 2011 -0400
+++ b/lib/sqlalchemy/orm/query.py	Wed Jul 27 18:07:58 2011 -0400
@@ -1535,7 +1535,7 @@
         # which is intended to wrap a the right side in a subquery,
         # ensure that columns retrieved from this target in the result
         # set are also adapted.
-        if aliased_entity:
+        if aliased_entity and not create_aliases:
             self.__mapper_loads_polymorphically_with(
                         right_mapper,
                         ORMAdapter(
@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

de0e272
e57cf91

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "0.7.2" to "0.6.9"
  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working orm labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.6.9 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working orm
Projects
None yet
Development

No branches or pull requests

1 participant