hey alchemers -

I want to direct your attention to some new features in trunk which  
I'll also be demonstrating at this years Advanced SQLAlchemy tutorial.

these features apply primarily to joined-table inheritance scenarios,  
and are in response to the need to specify criterion against  
subclasses as well as to join to/from joined-table classes where a  
specific subclass is required.

I've put some new docs at 
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_inheritance_joined_querying
 
  .

the two methods are with_polymorphic() and of_type().

with_polymorphic() may very well replace the need for select_table in  
almost all cases, and it creates the joins for you.  It allows  
filtering criterion to be against subclasses, *and* allows the mapper  
to load the full subclass instance without the need for a second query  
against the joined table.

Assume the usual Person / Engineer(Person) / Manager(Person) example :

        # query for Person objects, but specify criterion against Engineer
         
session 
.query 
(Person 
).with_polymorphic(Engineer).filter(Engineer.engineer_name=='dilbert')

        # query for Person objects but specify criterion against both Manager  
and Engineer
        session.query(Person).with_polymorphic([Engineer,  
Manager]).filter(or_(Engineer.engineer_name=='dilbert',  
Manager.manager_name=='dogbert'))

        # eagerly load all joined-table subclasses
        session.query(Person).with_polymorphic('*').filter(...filter on any  
table..).all()

of_type() is an operator applied to relations and is useful for  
joining, as well as the any() and has() operators.  Assume Company  
objects contain a collection called "employees' which contains Person  
objects:

        # join from Company to Engineer along its "employees" relation
         
session 
.query 
(Company 
).join 
(Company 
.employees.of_type(Engineer)).filter(Engineer.engineer_name=='dilbert')

        # query for Company objects where dilbert works
         
session 
.query 
(Company 
).join 
(Company 
.employees.of_type(Engineer).any(Engineer.engineer_name=='dilbert'))

So once again, all of these methods are designed to work with joined- 
table inheritance.   For concrete inheritance, we still arent  
generating those UNIONs automatically, though you can use  
with_polymorphic() if you send along a second argument which is a  
selectable to pull rows from.

If folks want to get on trunk and test out these features, that would  
be great.

- mike



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