On Oct 11, 2010, at 7:50 AM, Sebastian Elsner wrote:

>  have one table called 'Assets' with a 'category' (String) and 'created' 
> (DateTime) column. Now I would like to find the records created since a given 
> datetime for each category:
> 
> 
> This is what I thought would work (with a self-join):
> 
> session.query(Asset).join(Asset, and_(Asset.category == Asset.category, 
> Asset.created > specifiedDateTime)
> 
> But it does error with 'Cant find any foreign key relationships...'
> 
> How can I fix this? Or do you have a better idea how to accomplish the task?


You probably don't need the self join?  You can filter on multiple conditions.

session.query(Asset).filter(Asset.category == 
spefiiedCateogory).filter(Asset.created > specifiedDateTime)

or the equivalent using the and_ function

session.query(Asset).filter(and_(Asset.category == specifiedCategory, 
Asset.created > specifiedDateTime))

Mark

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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