jason kirtland <[EMAIL PROTECTED]> writes:

> A couple approaches come to mind:
> - map Obj to a select() with the restrictions baked in

I adapted the example the manual:

  http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_selects

It works great!  

The only thing that wasn't explicit from the example was that the
properties of the mapped objected has to use the columns of the select
object instead of the tables ones:

 -_next_join = (po_details_table.c.status_code_next
 +_pod_select = select([po_details_table],
 +                     and_(po_details_table.c.line_type == "J ",
 +                          po_details_table.c.line_no > 0)
 +                     ).alias("pod_select")
 +
 +_next_join = (_pod_select.c.status_code_next
                == order_rules_table.c.status_code)
 -_last_join = (po_details_table.c.status_code_last
 +_last_join = (_pod_select.c.status_code_last
                == order_rules_table.c.status_code)
 -mapper(PODetail, po_details_table,
 +
 +mapper(PODetail, _pod_select,
             properties=dict(status_rule_next=relation(OrderRule,
                                                       primaryjoin=_next_join),
                             status_rule_last=relation(OrderRule,

It would be nice if the example could illustrate this subtlety.
Otherwise, I love it.

Thanks!

-- 
Yannick Gingras

--~--~---------~--~----~------------~-------~--~----~
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