I'm confused at how to use *orm.aliased()*. I'm using declarative base.
I have a class defined from
Base.metadata.reflect(engine)
class Summary(Base):
__table__ = Base.metadata.tables['summary']
Now, I want to use that class in a self join
class JoinSummary(Base):
s1 = orm.aliased(Summary, name='summary1')
s2 = orm.aliased(Summary, name='summary2')
__select__ = sqlalchemy.select([...],
from_obj=s1.__table__.outerjoin(s2.__table__, s1.attr1 ==
s2.attr2)).where(...)
__table__ = __select__.alias('my_join_summary')
But as soon as I do *Session.query(Join.Summary.__select__)*, I get the
following error:
sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1066, "Not unique
table/alias: 'summary'", None)
I must not been using the aliased() as it should.
Your help will be much appreciated.
Thanks.
I am not sure how to do what I want: create a view class that I can use
later in Session.query().
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/Jk83OT3u0N8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.