Skip to content
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

sort_query cannot order by descending hybrid property #43

Closed
jpvanhal opened this issue Sep 14, 2013 · 0 comments
Closed

sort_query cannot order by descending hybrid property #43

jpvanhal opened this issue Sep 14, 2013 · 0 comments

Comments

@jpvanhal
Copy link
Collaborator

>>> import sqlalchemy as sa
>>> from sqlalchemy import create_engine
>>> from sqlalchemy.orm import sessionmaker
>>> from sqlalchemy.ext.declarative import declarative_base
>>> from sqlalchemy.ext.hybrid import hybrid_property
>>> from sqlalchemy_utils import sort_query
>>>
>>> engine = create_engine('sqlite:///')
>>> Base = declarative_base()
>>> Session = sessionmaker(bind=engine)
>>> session = Session()
>>>
>>> class User(Base):
...    __tablename__ = 'user'
...    id = sa.Column(sa.Integer, primary_key=True)
...    first_name = sa.Column(sa.Unicode(255))
...    last_name = sa.Column(sa.Unicode(255))
...
...    @hybrid_property
...    def full_name(self):
...        return self.first_name + ' ' + self.last_name
...
>>> query = sort_query(session.query(User), '-full_name')
>>> print query
SELECT "user".id AS user_id, "user".first_name AS user_first_name, "user".last_name AS user_last_name
FROM "user" ORDER BY "user".first_name || :first_name_1 || "user".last_name

Note that the query above is missing the DESC keyword.

SQLAlchemy's query syntax works fine:

>>> print session.query(User).order_by(sa.desc(User.full_name))
SELECT "user".id AS user_id, "user".first_name AS user_first_name, "user".last_name AS user_last_name
FROM "user" ORDER BY ("user".first_name || :first_name_1 || "user".last_name) DESC
@jpvanhal jpvanhal closed this as completed Oct 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant