On Feb 18, 2008, at 12:20 PM, jason kirtland wrote:
> To my knowledge you can't define a primary mapper against a free-form
> text SQL statement- without knowing what the columns will be, the  
> mapper
> can't set up the attribute mappings in the target class.
>
> There are probably other ways to set this up, but what I've done in  
> the
> past for a read-only query mapping is similar to how I've mapped some
> views: first, spell out a placeholder Table in SA with all the columns
> and types that the custom query returns.  Then map against the Table,
> but use the hand-written SQL for queries:
>
>   baz_table = Table('baz_placeholder', metadata, Column(...), ...)
>   mapper(Baz, baz_table)
>   sql = text('SELECT foo, bar FROM baz WHERE root_item = :root')
>
>   xyz_filtered_bazzes = \
>     session.query(Baz).from_statement(sql).params(root='xyz')


since its usually the WHERE clause where various craziness goes on,  
you can just define that part of the select() as text:

sometable.select().where("any kind of text goes here")

then just map to that.  the mapper only cares about the exported  
columns.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to