Hi,

>As long as you never use GROUP BY/DISTINCT, or aggregate functions, or
>non-trivial joins, SQLObject and friends work just fine. 
>
I do use GROUP BY with an ORM  successfully. In SQL, group by is mostly 
(only?) useful when you're using an aggregate function. With an ORM, at 
that point, the objects represented by the rows are different object to 
the underlying table. So I create a specific class for this and map it 
to the select.

Say you have a customer_value table with fields customer_id, region_id 
and value. You want to look at the total value in a region (I was about 
to say best customer, but that's actually tricky sql-wise). The query is 
select region_id, sum(value) from customer_value group by value. So, map 
that to RegionValue, and you can then use that as a normal class, e.g. 
RegionValue.query.get(77) You can even create relationships to your 
region table, so doing Region.get(77).value would actually compute the 
total value in SQL (although strictly that doesn't need group by).

DISTINCT doesn't really work with an ORM - because everything has an 
identity, everything is distinct already. There's still some benefit to 
using SQLAlchemy in non-ORM mode - queries are shorter as they leverage 
the relations defined in the model, and you can mix python values more 
freely into the query, without bind params and such.

Paul


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to