1

In the SQLAlchemy Tutorial

an example uses aliased:

>>> from sqlalchemy import func
>>> ua = aliased(User)
>>> q = q.from_self(User.id, User.name, ua.name).\
...     filter(User.name < ua.name).\
...     filter(func.length(ua.name) != func.length(User.name))

But it does not work in 0.6.1:

>>> from sqlalchemy import func

>>> ua = aliased(User)


Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    ua = aliased(User)
NameError: name 'aliased' is not defined
>>> ua = aliased(User)


Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    ua = aliased(User)
NameError: name 'aliased' is not defined
>>> ua = sqlalchemy.aliased(User)

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    ua = sqlalchemy.aliased(User)
NameError: name 'sqlalchemy' is not defined
>>> import sqlalchemy
>>> ua = sqlalchemy.aliased(User)

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    ua = sqlalchemy.aliased(User)
AttributeError: 'module' object has no attribute 'aliased'
>>> 
4

1 回答 1

10

Add:

from sqlalchemy.orm import aliased

class sqlalchemy.orm.aliased

于 2012-09-17T19:06:19.437 回答