[sqlalchemy] Re: Best way to handle in()

2007-08-28 Thread Paul Johnston

Hi,

foo = session.query(MainTable).filter_by(customer='CUSTNAME')
foo = foo.filter(ChildTable.c.othercolumn.in_('bar', 'baz', 'qux'))
  

You need to do the join; pass the name of the relation (not the target 
table) to join:

foo = foo.join('childtable').filter(ChildTable.c.othercolumn.in_('bar', 'baz', 
'qux'))

Paul

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Best way to handle in()

2007-08-28 Thread sdobrev

sorry for my bad sql, but where have u specified that link?
u should have something like

 foo.filter( (Main.chidlid==Child.childid) 
Child.othercolumn.in_('a', 'b', 'c') )
or 
 foo.join( child).filter( Child.othercolumn.in_('a', 'b', 'c') )

(warning: the exact syntax may or may not be this, do check)

On Tuesday 28 August 2007 22:58:11 Kirk Strauser wrote:
 I have mappers configured for main and child, and those tables
 are linked on main.childid=child.childid.  How can I use in() to
 get rows where child.othercolumn is in a list of values?  I'd like
 to do something like:

 foo = session.query(MainTable).filter_by(customer='CUSTNAME')
 foo = foo.filter(ChildTable.c.othercolumn.in_('bar', 'baz', 'qux'))

 Or, even better, some variant on:

 foo = session.query(MainTable).filter_by(customer='CUSTNAME')
 foo = foo.filter(othercolumn in ('bar', 'baz', 'qux'))

 When I try to do that, though, I get SQL like:

 SELECT main.value AS main_value, main.childid AS main_childid,
 child.childid AS child_childid, child.othercolumn AS
 child_othercolumn
 FROM testing.main, testing.child
 WHERE child.othercolumn IN (%(child_othercolumn)s,
 %(child_othercolumn_1)s, %(child_othercolumn_2)s) ORDER BY
 main.value

 which is really doing a cartesian join and never enforcing
 main.childid=child.childid.  Is there another way I should be
 approaching this?



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---