[PonyORM-list] The docs don't seem to cover this query type

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Sun Feb 16 15:32:17 UTC 2014

Hi Matthew!

Your query should be written in one of the following ways (the first query
is the most efficient):

1. select(a for a in A for b in a.bs if max(b.status) == 'whatever' and
min(b.status) == 'whatever')

2. select(a for a in A if max(a.bs.status) == 'whatever' and
min(a.bs.status) == 'whatever')

3. select(a for a in A if 'whatever' in a.b.status and not exists(b for b
in a.bs if b.status != 'whatever'))

Pony currently doesn't support automatic transaltion of all(), but in
future we'll add this feature, and the result of translation will be the
same as in one of the the queries above.


On Sun, Feb 16, 2014 at 5:26 PM, Matthew Bell
<matthewrobertbell at gmail.com>wrote:

> Say I have 2 entities with a one to many relationship:
>     class A(db.Entity):
>         bs = set('B')
>     class B(db.Entity):
>         a = Required('A')
>         status = Required(unicode)
> I then want to query for all "A", that have Bs that all have the status
> "whatever".
> How I assumed it could be done:
>     select(a for a in A if a.bs.status == 'whatever')
> or
>     select(a for a in A if all(b.status == 'whatever' for b in a.bs))
> But neither work. What is the "pony way" of doing this?
> A python example of what I mean (I obviously would like to do it properly
> all in pony though):
>     for a in models.A.select():
>         if all(b.status == 'whatever' for b in a.bs):
>             yield a
> Thanks in advance for any guidance.
> --
> Regards,
> Matthew Bell
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20140216/46b7033e/attachment.html>

More information about the ponyorm-list mailing list