It's this:
 SELECT "id", "imei", "name", "heartbeat", "online", "mode",
"refresh_interval" FROM "devices" ORDER BY "heartbeat" DESC
 SELECT "id", "lat", "lon", "time", "device_id", "mode",
"response_num", "alt" FROM "locations" WHERE "device_id" IN (2, 1)
ORDER BY "id"

Just tested what happens if I only have one device:
 SELECT "id", "imei", "name", "heartbeat", "online", "mode",
"refresh_interval" FROM "devices" ORDER BY "heartbeat" DESC
 SELECT "id", "lat", "lon", "time", "device_id", "mode",
"response_num", "alt" FROM "locations" WHERE "device_id" = 1 ORDER BY
"time" DESC LIMIT 1

The generated SQL is the correct one for this scenario, but I have
multiple devices (queried using Devices.all), so it has something to
do with lazy/eager loading.

 SztupY

On júl. 25, 18:07, Kevin Watt <[email protected]> wrote:
> What's the sql that you're seeing?
>
> At first I thought you were using HABTM and needed to query the :through 
> relationship, but its just has n, it should be pretty simple (i.e. work as 
> you expect)
>
> Ciao,
> Kevin
> "Desire makes everything blossom; possession makes everything wither and 
> fade." - Proust

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