ActiveRecord::UnknownAttributeReference: Query method called with non-attribute argument(s)

I’m trying to use spatial distance in my Rails app, but I keep running into the "ActiveRecord::UnknownAttributeReference: Query method called with non-attribute argument(s)" error when I try to use the order method. Here’s my code: def nearby_locations third_party_location_query = ThirdPartyLocation.where(id: id).select(‘geom’).to_sql third_party.organisation.locations.active. select("locations.*, ROUND(ST_DistanceSphere(locations.geom, (#{third_party_location_query}))::numeric, 0)::integer distance"). order("locations.geom <-> (#{third_party_location_query})"). limit(10).as_json(methods: [:distance]) end I understand… Read More ActiveRecord::UnknownAttributeReference: Query method called with non-attribute argument(s)

Is there an Aggregate function that functions similarly to STUnion()?

I see that there is something called STUnion() which will union the result of one geography type with another. But is is possible to do that over an entire data set like an aggregate function? Or if not, is there a performant equivalent? >Solution : SQL Server offers some aggregate methods on geometries, including UnionAggregate… Read More Is there an Aggregate function that functions similarly to STUnion()?