P
P
Pavel2017-09-24 07:18:53
Flask
Pavel, 2017-09-24 07:18:53

How to set column_property?

It doesn't work like that

user_count = column_property(
        db.session.query(func.count(User.id))
    )
# RuntimeError: application not registered on db instance and no application bound to current context

There are generally some problems with mapping. The error is not related to this table at all.
user_count = column_property(
        User.query.with_entities(func.count(User.id))
    )

This is how it works
user_count = column_property(
        select([func.count(User.id)])
    )

But here is the problem with the jane
user_count = column_property(
        select([func.count(User.id)])
             .join(User.attrs)
    )
# sqlalchemy.exc.ArgumentError: FROM expression expected

Why does model query not work and what to do with select?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question