Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
vladgurovich opened this Issue · 0 comments

1 participant

@vladgurovich

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

bounds=Bounds.from_point_and_radius(home,5)
stores=Store.find :all, :include=>[:reviews,:cities] :bounds=>bounds
stores.sort_by_distance_from(home)

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
Something went wrong with that request. Please try again.