On Aug 25, 2008, at 12:22 PM, Hermann Himmelbauer wrote:

>
> Hi,
> I'm wondering if the following is possible with mappers:
>
> I have two tables A and B, whereas B is referenced by A. What I need  
> is a
> special mapper for A that returns all referenced rows in B except  
> those, that
> have a specific value in one column of the row, e.g.:
>
> Table A:
> id, sometext, reftoB
> 1, xyz, 1
> 2, abc, 2
>
> Table B:
> id, sometext
> 1, foo
> 2, NOTTHISONE <- Should not be returned by the mapper
>
> Is there a simple way to achieve this?
>

I'm not 100% clear on what you're asking since it seems like you are  
looking for a list of "A" based on something in B, but you said  
"returns all referenced rows in B".   If you just wanted all Bs  
without "sometext=NOTTHISONE" thats just query(B).filter(B.sometext! 
='NOTTHISONE').

Assuming you want the "A"s, the usual way to do this is to use a NOT  
EXISTS clause, which the ORM provides most easily along a relation().   
If A has a relation to B which joins on reftoB, you'd say:

session.query(A).filter(~A.b.has(B.sometext=='NOTTHISONE'))




--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to