On May 12, 2008, at 1:48 PM, [EMAIL PROTECTED] wrote:
> >>>> cls.query.left_bracket().filter_or(cls.y == >>>> 17).filter_or(cls.x==27).right_bracket() >>>> is clearer than this: >>>> cls.query.filter(or_(cls.y == 17, cls.x==27)) >>> >>> it's not. it's not about replacing the or_. noone should use it >>> that way... >>> >>> u have horses and owners with houses and hats. >>> give me horses (whose owners have a hat of size 10 and color >>> green) or (whose owners have a house of color red) or (have no >>> tail) >> >> filter(or_( >> horses.owners.any(hatsize=10, color='green'), >> horses.owners.any(and_(owners.house_id==houses.house_id, >> houses.color=='red')), >> horses.tail == None >> )) > > ahha, so thats how joins can go inside or_(). > isn't this (i guess it has subselects) more expensive than a single > plain or/and clause? if you wanted to spell it out with JOIN you can do that too - house_owners = aliased(Owner) hat_owners = aliased(Owner) query(Horse).outerjoin((house_owners, 'owners'), 'houses').\ outerjoin((hat_owners, 'owners'), 'hats').\ filter(or_( and_(Hat.size==10, Hat.color=='green'), House.color=='red', Horse.tail == None )) im not sure but you might be also able to disable aliasing on House/ Hat if you said query.outerjoin('owners', (House, 'houses'), aliased=True)...thats a little more experimental tho. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---