2

Is it possible to subclass models and inherit the superclass's properties so in the end I have the models:

class User
- class Student : User
- class Teacher : User



With the intention of creating this: https://ryanbigg.com/2008/09/multiple-user-access-levels

  • 4
    Unfortunately it's impossible cause model class should be `final`. Also inheritance isn't a good idea while you're working with codables, cause super's properties wouldn't be encoded without manual code. So just create these two models separately :) – imike Mar 11 '19 at 20:40
  • 1
    I would personally create a `User` model with a `status` property. The type of the property could be a `Status` enum. I've done this before and it works wonderfully. – Caleb Kleveter Mar 12 '19 at 19:11
  • 1
    You could create a protocol. `protocol User : Codable { //properties }` – LoVo Apr 02 '19 at 10:26

1 Answers1

1

After reading the Discord chat as of March 1, 2019 there is an open issue here for fluent: https://github.com/vapor/fluent-kit/issues/8.