The models BarberShop (table barber_shops)
and Barber (table barbers)
all exist. In rails c
after
x = Barber.new and x.include? :barbershop => true.
So the association should be set up correctly. When I try to save I get the
Name error Uninitialized constant BarberShop::Barber.
I know it is something more than likely easy that I am having trouble finding. For example I learned today with a has-many-through-association
the order (in the model) of the associations matter where a must be listed to get b - i.e.
has_many :a
has_many :b, through: :a
The models are as below -
Barber < ApplicationRecord
belongs_to :barbershop
has_many :appointments
has_many :customers, through: :appointments
BarberShop < ApplicationRecord
has_many :barbers
end
#schema in db
create_table "barber_shops", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "barbers", force: :cascade do |t|
t.string "name"
t.string "email"
t.integer "barbershop_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["barbershop_id"], name: "index_barbers_on_barbershop_id"
end