1

SQLAlchemy チュートリアル

例では次を使用します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))

しかし、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

追加:

from sqlalchemy.orm import aliased

クラス sqlalchemy.orm.aliased

于 2012-09-17T19:06:19.437 に答える