Hi I'm trying to set up a many to many relationship in my app. I have two models Count.rb
class Count < ApplicationRecord
has_many :users, through: :counts_users
end
users.rb
:
class User < ApplicationRecord
has_many :counts, through: :counts_users
end
and counts_users.rb
:
class CountsUser < ApplicationRecord
belongs_to :user
belongs_to :count
end
Now I can create a count
Count.new(message: 'hello')
but if I then do
Count.last.users << User.last
I get the error ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :counts_users in model ErrorCount
I assume I've done something wrong setting up the association, but I'm not sure what?