Hi

I'm confronted with the following situation:

I have two entities:

Account 1:n AccountEntry

AccountEntry has a column (and property) 'amount'.

Now I'd like to implement a @hybrid_property.expression 'balance' on Account
which uses func.sum(AccountEntry.amount) to calculate the account's balance.

When I do:

    @balance.expression
    def balance(cls):
        return func.sum(AccountEntry.amount)

sqlalchemy.exc.ProgrammingError: (ProgrammingError) (b'ERROR', b'42803',
b'aggregates not allowed in WHERE clause')

which is ok, since you have to have a sub-select like

select * from accounts as a where (select sum(ae.amount) as balance from
account_entries as ae where ae.account_id = a.id) > 0

Now my question: How to achieve this using @hybrid_property.expression?
Which query fragment I have to return?

Best Regards,
Florian

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to