Perhaps this is just
Sti + namespace - Rails - Ruby-Forum
coming back to bite me – I suspect I’m missing a trivial declaration.
==== Error message (note that NOAA is an STI subclass of WeatherStation)
ActiveRecord::AssociationTypeMismatch (WeatherStation(#2169635200)
expected, got NOAA(#2185634180)):
==== Source of the error (station is, in fact, an NOAA object)
PremiseWeatherStation.create(:premise => self, :weather_station =>
station)
==== Models
class Premise < ActiveRecord::Base
has_many :premise_weather_stations, :dependent => :destroy
has_many :weather_stations, :through => :premise_weather_stations
…
end
class PremiseWeatherStation < ActiveRecord::Base
belongs_to :premise
belongs_to :weather_station
end
WeatherStation is the ‘parent’ of STI models
class WeatherStation < ActiveRecord::Base
has_many :premise_weather_stations, :dependent => :destroy
has_many :premises, :through => :premise_weather_stations
…
end
NOAA is an STI subclass of WeatherStation
class NOAA < WeatherStation
…
end
==== Tables:
create_table “premise_weather_stations”, :force => true do |t|
t.integer “premise_id”
t.integer “weather_station_id”
…
end
create_table “premises”, :force => true do |t|
…
end
create_table “weather_stations”, :force => true do |t|
t.string “callsign”
t.string “type” # for STI support
…
end
====
I don’t think I’m doing anything “un-RAILs-ish”. Any idea what I’m
missing?
- ff