[sqlalchemy] Re: Proper way to use case() in a filter()?

2009-08-12 Thread Randy Syring
Mike,

Thank you for the reply.  That looks very close to what I have.  At the very
least, my understanding about what I should be able to do looks correct.  I
will do some further testing and examination and post back with details.

Thanks again.

--
Randy Syring
RCS Computers  Web Solutions
502-644-4776
www.rcs-comp.com

Whether, then, you eat or drink or
whatever you do, do all to the glory
of God. 1 Cor 10:31


On Tue, Aug 11, 2009 at 10:04 PM, Mike Conley mconl...@gmail.com wrote:

 Not much detail to tell what is wrong. Here is a contrived but working
 example based on one of my examples:


 ut = Table('user',meta,
 Column('uid',String,primary_key=True),
 Column('name',String)
 )

 kt = Table('keywords',meta,
 Column('keyword',String,primary_key=True)
 )

 ukt = Table('userkeywords',meta,
 Column('uid',String,ForeignKey('user.uid')),
 Column('kw',String,ForeignKey('keywords.keyword'))
 )

 class User(Base):
 __table__ = ut
 keywords = relation('Keyword',
 secondary=ukt,
 backref='users')
 def __repr__(s): return User %s:%s % (s.uid,s.name)

 class Keyword(Base):
 __table__ = kt
 def __repr__(s): return Keyword %s % s.keyword

 q = session.query(User).\
 select_from(join(ut,ukt,ut.c.uid==ukt.c.uid)).\
 filter(case([(ut.c.uid=='mike','M'),
 (ut.c.uid=='sue','F')],
 else_='X') == 'M')


 --
 Mike Conley


 


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



[sqlalchemy] Re: Proper way to use case() in a filter()?

2009-08-11 Thread Mike Conley
Not much detail to tell what is wrong. Here is a contrived but working
example based on one of my examples:


ut = Table('user',meta,
Column('uid',String,primary_key=True),
Column('name',String)
)

kt = Table('keywords',meta,
Column('keyword',String,primary_key=True)
)

ukt = Table('userkeywords',meta,
Column('uid',String,ForeignKey('user.uid')),
Column('kw',String,ForeignKey('keywords.keyword'))
)

class User(Base):
__table__ = ut
keywords = relation('Keyword',
secondary=ukt,
backref='users')
def __repr__(s): return User %s:%s % (s.uid,s.name)

class Keyword(Base):
__table__ = kt
def __repr__(s): return Keyword %s % s.keyword

q = session.query(User).\
select_from(join(ut,ukt,ut.c.uid==ukt.c.uid)).\
filter(case([(ut.c.uid=='mike','M'),
(ut.c.uid=='sue','F')],
else_='X') == 'M')


-- 
Mike Conley

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