My problem is quite similar to this, but with some problematic differences.
I'd like to make two relationships between User
and Service
- one-to-many relationship of ownership and many-to-many relationship of saving.
My Service model:
class Service < ApplicationRecord
belongs_to :user #ownership
belongs_to :category
has_many :time_slots
has_many :pictures
has_and_belongs_to_many :saving_users, class_name: 'User' #saving
end
My User model:
class User < ApplicationRecord
has_many :services #ownership
has_many :reservations
has_many :time_slots, through: :reservations
has_and_belongs_to_many :saved_services, class_name: 'Service' #saving
end
Trying to get @user.saved_services
I receive this error:
PG::UndefinedTable: ERROR: relation "services_users" does not exist LINE 1: SELECT "services".* FROM "services" INNER JOIN "services_use...
I dropped database and built it again, but this didn't help me.
Unfortunately this solution also doesn't work.