With dm-aggregates, size does not produce the expected answer with a query
containing limit.

Simple example:>> 3.times {Thing.gen}
=> 3
>> Thing.all(:limit=>2).size
=> 3
>> Thing.all(:limit=>2).map{1}.size   # my new fave idiom until this bug is
fixed
=> 2

Queries w/ limit come up a lot when working with pagination, so it would be
really nice to get this fixed.
(Someone writing MVC Merb code should not have to know about this
weirdness.)

This issue is with the data_objects/mysql adapter.  The bug is that DM
translates the query
"Thing.all(:limit=>2).size" into:

"SELECT COUNT(*) FROM `things` LIMIT 2"

which MySql interprets as ( SELECT COUNT(*) FROM `things` ), return one row,
then LIMIT 2,
and which Postgres complains as non-kosher SQL.

Note that ActiveRecord returns Thing.all(:limit=>2) as an Array, so .size()
works just fine there (it's buggy though with its auto-conversion of
find_by_sql to count_by_sql).

It seems like the fix would involve something like translating the query
into
"SELECT COUNT(*) FROM (SELECT 'things' LIMIT 2) tmp"

and translating something like

"SELECT SUM(mass) FROM `things` LIMIT 2"

into

"SELECT SUM(tmp.mass) FROM (SELECT `things` LIMIT 2) tmp"

I imagine it would get more complex with nested queries / associations.

Anyone else have any thoughts?

Thanks,
Gary

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

Reply via email to