On Mar 31, 2008, at 12:02 PM, pyplexed wrote:
> > The continuing adventures of a newbie SA user... > > Could anyone tell me if there is a simple way of setting up a query > which takes an object as an argument and checks for the existence of > an object in the database? by primary key ? assuming as below you don't have any prior knowledge of the object's properties or type, sess .query (obj.__class__).get(object_mapper(obj).primary_key_from_instance(obj)) > I know I can construct a query hard coding attributes to filter on, > but I'm sure there is a better way to do this. the above is a little ugly so you could make a function that does it, given any object (or even make it a classmethod on a base class). > Ideally, the query would need to handle attributes containing multiple > objects expressing many to many relationships. Im not entirely sure what this means. You'd like to query for an object based on its many-to-many association to another object ? This would look like: sess .query (DesiredClass ).filter(DesiredClass.somerelation.contains(some_given_object)).all() --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
