I have a Color model:
class Color < ApplicationRecord
belongs_to :sector
A sector model:
class Sector < ApplicationRecord
has_many :colors
I created a join table like:
class CreateJoinTableColorSector < ActiveRecord::Migration[6.0]
def change
create_join_table :color, :sectors do |t|
t.index %i[color_id sector_id]
t.index %i[sector_id colore_id]
end
end
end
Now I want to get all the Colors who belongs to a specific sector. I tried :
Color.joins(:sectors).where({ sector: sector })
But it returns me an error → uninitialized constant Color::Sectors