I have 2 models UnitPlate
& PlantPlate
which are a part of STI(Single table inheritance). I need many-to-many association with them. Is the below way of has_many: through and STI correct. I have the below models. Facing some issues in migrations with the below approach
Parent Model
class Plate < ActiveRecord::Base
end
Submodel 1
class UnitPlate < Plate
has_many :unit_and_plant_plates, :dependent => :destroy
has_many :plant_plates, through: :unit_and_plant_plates
end
Submodel 2
class PlantPlate < Plate
has_many :unit_and_plant_plates, :dependent => :destroy
has_many :unit_plates, through: :unit_and_plant_plates
end
Associated Model
class UnitAndPlantPlate < ActiveRecord::Base
belongs_to :unit_plate
belongs_to :plant_plate
end
Migration
class CreateTableUnitAndPlantPlates < ActiveRecord::Migration
def change
create_table :unit_and_plant_plates do |t|
t.belongs_to :unit_plate
t.belongs_to :plant_plate
t.timestamps
end
add_index :unit_and_plant_plates, :unit_plate_id
add_index :unit_and_plant_plates, :plant_plate_id
end
end
Error during migrations
rake aborted!
/Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/trace_output.rb:16:in `block in trace_on': invalid byte sequence in US-ASCII (ArgumentError)
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/trace_output.rb:14:in `map'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/trace_output.rb:14:in `trace_on'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:340:in `trace'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:187:in `display_error_message'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:174:in `rescue in standard_exception_handling'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/bin/rake:19:in `load'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/bin/rake:19:in `<main>'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/ankitgupta/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'
Is this way of defining the has_many through correct?