Forum: Ruby on Rails acts_as_mappable :through relationship is not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
47d49f45d93415de3651d9578d0350fb?d=identicon&s=25 john smith (Guest)
on 2009-04-22 09:30
(Received via mailing list)
Hello-
I have two models (User and Locations). One user can have  multiple
locations (home, office etc..) The location table has the lat and
lngs.

class User < ActiveRecord::Base
     has_many :locations
     acts_as_mappable :through => :locations

class Location < ActiveRecord::Base
    belongs_to :user
    acts_as_mappable

Now, when I do User.find_within(500. :origin => ..), It fails with the
following error:
                Mysql::Error: Unknown column 'users.lat' in 'field
list':

So, it seems that the :through relationship is not working. Can
someone pelase help me.

thanks
-John
782b01570270ab10543bc25a258d7ea8?d=identicon&s=25 Dmitry Sokurenko (Guest)
on 2009-04-22 11:18
(Received via mailing list)
John,

acts_as_mappable is not an association, it's a custom macro and it
doesn't support :through option.

So remove it from the User model. And to find all users near some
point use something like:

  Location.find_within(500. :origin => ..., :include => :user).map
(&:user).uniq

Dmitry
This topic is locked and can not be replied to.