On Aug 25, 2009, at 2:08 PM, Mike Orr wrote:

> Can you give an example of this?  I've read about the features but I
> don't quite have my head around them.  Are you talking about mappers
> that leave some columns unmapped, or queries that return calculated
> results alongside ORM objects, etc?

Let's say you have articles that map to authors. You set it all up  
using mapper with relations, each article has an author, and each blog  
might have multiple authors related. You eventually need to do more  
low-level SQL type queries. So say instead of doing:

stories =  
Session 
.query(Article).join(Article.blog).filter(Blog.name=='Tech').all()

You then realize, well, you don't really need the ORM, its slowing you  
down, you just want all the id's and titles. Instead of using the  
whole SQL table query stuff, in SA 0.5 you can do:

stories = Session.query(Article.id,  
Article.title).join(Article.blog).filter(Blog.name=='Tech').all()

So we can just select multiple attributes, and the rest of the lingo  
stays the same. We're still utilizing the 'blog' back-ref property on  
the Article that we setup with the SA ORM level mapper stuff. Of  
course, instead of Article objects back, we get an AttributeTuple list  
of rows just like when you do a lower level SA SQL query. It's verrrry  
slick.

Of course, as with the lower level of SA, you have the same  
limitations, these are just row-tuple's now with 2 attributes, no lazy  
loading of relations, etc. Which is fine for me as I want my speed and  
specific attributes. You can even combine them, like so:

stories = Session.query(Article, Blog.id).join(Article.blog)....
for article, blog_id in stories:
     etc....

And yes, Article will be the fully SA ORM mapped object.

It's also waaay shorter than doing the query with all the table  
objects and such. :)

Cheers,
Ben

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to