King Simon-NFHD78 wrote:
You'll have to give it a table name, which will have the effect of
defining a Table object even though no such table exists in the
database, but I don't think this matters. Then you could use the query
that Mike suggested to actually retrieve rows
Thanks, Simon - I ended up doing something much like this. I went down
a slightly different path before I realized I was basically doing what
you suggested. I ended up with the following. I'm not sure what sort
of side effects I'd see from this (other than, perhaps, ridicule :), but
it does work the way I want and seems safe enough if used strictly in
this way. Note, 'real_vehicle' is not an actual table in the database.
I think I'll retool this using the declarative_base to see how that
works out.
real_vehicle = Table('real_vehicle', metadata,
Column('vehicle_id', Integer, primary_key=True),
Column('vehicle_name', String),
Column('vehicle_description', String),
Column('vehicle_type', String),
)
class Vehicle(object):
pass
mapper(Vehicle, real_vehicle)
vehicle_query = """
select
v.vehicle_id as 'vehicle_id',
v.name as 'vehicle_name',
v.description as 'vehicle_description',
vt.name as 'vehicle_type'
from
vehicle v,
vehicle_type vt
where
vt.vehicle_type_id = v.vehicle_type_id
and v.vehicle_id = :vehicle_id
"""
q = s.query(Vehicle).from_statement(vehicle_query).params(vehicle_id=1)
for vehicle in q:
print vehicle.vehicle_id, vehicle.vehicle_name,
vehicle.vehicle_description, vehicle.vehicle_type
Thanks again, Simon and Michael, for the help!
--
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.