Geokit and Polymorphic Address

26 views
Skip to first unread message

badnaam

unread,
May 29, 2010, 7:29:34 PM5/29/10
to Thinking Sphinx
My Store model is like..

has_one :address, :as => :addressible, :dependent => :destroy

The Address model has lat and lng columns as floats

If I do this in my define index..

has 'RADIANS(addressible.lat)', :as => :latitude, :type => :float
has 'RADIANS(addressible.lng)', :as => :longitude, :type
=> :float


I get this errror

sql_range_query: Unknown column 'addressible.lat' in 'field list'

What am I doing wrong here?

Thanks

Pat Allan

unread,
May 30, 2010, 1:58:57 AM5/30/10
to thinkin...@googlegroups.com
You'll need to make sure the join is included... try adding the following:
has addressible.id, :as => :addessible_id

This forces the join.

Cheers

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
>

badnaam

unread,
May 30, 2010, 4:18:04 PM5/30/10
to Thinking Sphinx
Thanks Pat.

I tried this..

has addressible(:id), :as => :addessible_id

since it wont take "id" and it still throws the same error.

However what work is this..changing address to adresses. But this
should not be the case since the model has_one address.
has 'RADIANS(addresses.lat)', :as => :latitude, :type
=> :float
has 'RADIANS(addresses.lng)',:as => :longitude, :type
=> :float

Pat Allan

unread,
May 30, 2010, 8:41:39 PM5/30/10
to thinkin...@googlegroups.com
While it is a has_one association, the table name is addresses, and ActiveRecord won't give the table an alias unless it's referenced more than once, hence why it's plural (the table name) instead of singular (the association name).

Good to know you've got it figured out.

Cheers

--
Pat

Reply all
Reply to author
Forward
0 new messages