# Geokit - using :through to connect models

**URL:** <https://www.ruby-forum.com/t/geokit-using-through-to-connect-models/161076>\
**Category:** Rails\
**Created:** [February 23, 2009, 8:12am UTC](https://www.ruby-forum.com/t/geokit-using-through-to-connect-models/161076 "2009-02-23T08:12:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [February 23, 2009, 8:12am UTC](https://www.ruby-forum.com/t/geokit-using-through-to-connect-models/161076/1 "2009-02-23T08:12:09Z")

</div>

hello…

i am currently trying to use :through to attach two of my models  
together using geokit. for some reason, i am running into a problem:

ArgumentError: Unknown key(s): as

i have two models, one that is geocoded, and one that belongs to that  
model. the models look like:

,----[employer.rb]  
| class Employer \< ActiveRecord::Base  
| acts\_as\_mappable  
| before\_validation\_on\_create :geocode\_address  
|  
| has\_many :internships  
| belongs\_to :account  
| belongs\_to :role  
|  
| private  
| def geocode\_address  
| geo=GeoKit::Geocoders::MultiGeocoder.geocode(address1 + " " + city + " " + state + " " + zip)  
| errors.add(:address, “Could not Geocode address”) if !geo.success  
| self.lat, self.lng = geo.lat,geo.lng if geo.success  
| end  
|  
| end  
`----

and an internship:

,----[internship.rb]  
| class Internship \< ActiveRecord::Base  
| has\_many :internship\_categories  
| belongs\_to :employer, :polymorphic =\> true  
| acts\_as\_mappable :through =\> :employer  
| end  
`----

it seems like there is an intermediary object in the docuements called  
‘:locatable’ that connects the the two together, but i just can’t get  
how that is being called, or what i am supposed to do with it.

no matter where i put it, i end up with this error:

ArgumentError: Unknown key(s): as

if i remove: “:as =\> :locatable” i end up with a problem in that the  
model doesn’t have :lat or :lng, which makes me think that  
the :through is not working at all.

please let me know how to attack this…

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [February 23, 2009, 7:12pm UTC](https://www.ruby-forum.com/t/geokit-using-through-to-connect-models/161076/2 "2009-02-23T19:12:59Z")

</div>

I think your trouble here is with the polymorphic association. (Why do  
you need it - is there another model that has\_one or has\_many  
:internships :as =\> :employer?)

Try either removing :polymorphic =\> true if you don’t need it, or  
adding :as =\> :employer to the Employer’s has\_many :internships line.

[http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations](http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations)

On Sun, Feb 22, 2009 at 11:12 PM, Sergio R.

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [February 24, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/geokit-using-through-to-connect-models/161076/3 "2009-02-24T16:34:29Z")

</div>

thanks for your help!

i am gonna have to look into this a little bit more to get my head  
around this…

thanks!
