Hi!
I've got the following problem:
http://stackoverflow.com/questions/3327394/datamapper-first-method-is-querying-the-whole-relation
:
I have some devices, which have multiple locations, and I usually only
want the latest location of a device. The problem is that the
generated SQL for the above line will query all locations for the
device not just the latest one (and a device can have 10-20k
locations). This is clearly not optimal, so I'm asking: am I doing
something wrong? Or datamapper works this way and I have to resort
back to plain SQL? Is there a better workaround?
---
I have the following data schema:
class Location
property :lat, Integer
property :lon, Integer
property :time, Time
belongs_to :device
end
class Device
#some properties
has n, :locations
def lat # and lon
locations.first(:order => [:time.desc]).lat
end
end
Here a call to d.lat (where d is a Device) will result in a query of
all the locations, instead of only the first matching one.
Thanks
--
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.