Michael Chambliss wrote: > > vehicle_query = """ > select > v.vehicle_id as vehicle_id, > v.name as vehicle_name, > v.description as vehicle_description, > vt.name as vehicle_type, > vs.name as vehicle_status, > v.modify_dttm as vehicle_modify_dttm > from > vehicle v, > vehicle_type vt, > vehicle_status vs > where > v.vehicle_id = :vehicle_id > and vs.vehicle_status_id = v.vehicle_status_id > and vt.vehicle_type_id = v.vehicle_type_id > """ > > class Vehicle(object): > def __init__(self, vehicle_id, vehicle_name, vehicle_description, > vehicle_type, vehicle_status, vehicle_modify_dttm): > self.vehicle_id = vehicle_id > self.vehicle_name = vehicle_name > self.vehicle_description = vehicle_description > self.vehicle_type = vehicle_type > self.vehicle_status = vehicle_status, > self.vehicle_modify_dttm = vehicle_modify_dttm > > def __repr__(self): > return "<Name('%s')>" % (self.vehicle_name) > > # Here's where I get sideways... > # Obviously this won't work, but I'm not sure how to map the query to > the class > mapper(Vehicle, ??query??)
the mapper really requires Table metadata in order to be mapped. vehicle = Table("vehicle", metadata, autoload=True) vehicle_type = Table("vehicle_type", metadata, autoload=True) vehicle_status = Table("vehicle_status", metadata, autoload=True) j = vehicle.join(vehicle_type, vehicle.c.foo==vehicle_type.c.bar).join(vehicle_status, vehicle.c.bat==vehicle_status.c.bat) mapper(Vehicle, j) I think you'd find that from_statement() is a lot more work for the example query you have above. With such a mapping, you'd get the base set of rows with query(Vehicle).all() and simple filtering with query.(Vehicle).filter_by(vehicle_status_description='foo') , for example. But from_statement can be invoked at any point. > from > vehicle v, > vehicle_type vt, > vehicle_status vs > > metadata.bind = engine > > q = s.query(Vehicle).from_statement(vehicle_query).params(vehicle_id=123) > > for vehicle in q: > print vehicle.vehicle_id, vehicle.vehicle_name > > #... > > Thanks, > Mike > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@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. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.