0
votes

I have a user model and 3 subclasses using Single Table Inheritance. Owner, Client and Admin. (The type column has been added to the user table).

#user.rb
class User < ApplicationRecord
    devise :database_authenticatable,:registerable,
         :jwt_authenticatable,
         jwt_revocation_strategy: JWTBlacklist

end

#client.rb
class Client < User
end

#admin.rb
class Admin < User
end

#owner.rb
class Owner < User
  has_many :clubs
end

#club.rb
class Club < ApplicationRecord
  belongs_to :owner
  has_one :address
  has_many :courts
end

The Owner model has a has_many relationship with the Club model. When I log into my app as an owner, and then try to add a new Club. Using

@club= current_user.clubs.create!(club_params)

I get the following error.

ActiveRecord::StatementInvalid (SQLite3::SQLException: no such table: main.owners: INSERT INTO "clubs" ("owner_id", "created_at", "updated_at") VALUES (?, ?, ?)):

Is there some way to make it search the users table instead?

1
Could you please add your club model. I suspect the bug is in there. - Austio
I've added the club model - Dontreadonme

1 Answers

0
votes

found the answer here Rails STI and has_many through association not working, SQLException: no such table

I had to use

spring stop

and reset the database with

rails db:reset