Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added support for :through associations in XXX.sort_by_distance_from #26

vladgurovich opened this Issue Jan 25, 2011 · 0 comments


None yet
1 participant

I needed to have results include calculated distances, so per your docs I tried to use

stores=Store.find :all, :include=>[:reviews,:cities] :bounds=>bounds

Where Store has act_as_mappable :through => :location

Unfortunately sort_by distance_from doesnt work with :through associations, but you can fix it with the following
In acts_as_mappable.rb in sort_by_distance_from function replace the following line:

e.send("#{distance_attribute_name}=", e.distance_to(origin,opts))

with the following 2 lines:

responder = e.through.blank? ? e : e.send(e.through)
e.send("#{distance_attribute_name}=", responder.distance_to(origin,opts))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment