I am trying to do what is described here:
http://freelancing-god.github.com/ts/en/geosearching.html
Except rather than having latitude and longitude columns on my model, I want to do:
class Post
has_one :location, :as => :locationable
end
class User
has_one :location, :as => :locationable
end
class Location
belongs_to :locationable, :polymorphic => true
end
so that User and Post can both have location records set by locationable_type and locationable_id… So I did the following in my Post model:
define_index do
has locationable(:id), :as => :locationable_id
has "RADIANS(locations.lat)", :as => :latitude, :type => :float
has "RADIANS(locations.lng)", :as => :longitude, :type => :float
end
but I get an Unknown column in ‘field list’ error…
What am I doing wrong?
I figured it out.. This line:
Was supposed to be forcing a join… but it couldn’t because there is no such thing as locationable for a post record.. It has_one location.. So it needed to be:
and now it works.