【问题标题】:Server Side Swift Vapor - Model inheritance服务器端 Swift Vapor - 模型继承
【发布时间】:2019-08-02 05:36:09
【问题描述】:

是否可以子类化模型并继承超类的属性 所以最后我有模型:

类用户
- 班级学生:用户
- 班主任:用户



打算创建这个:https://ryanbigg.com/2008/09/multiple-user-access-levels

【问题讨论】:

  • 不幸的是这是不可能的,因为模型类应该是final。当您使用可编码时,继承也不是一个好主意,因为如果没有手动代码,就不会对 super 的属性进行编码。所以只需分别创建这两个模型:)
  • 我会亲自创建一个具有status 属性的User 模型。属性的类型可以是 Status 枚举。我以前做过,效果很好。
  • 你可以创建一个协议。 protocol User : Codable { //properties }

标签: swift vapor server-side-swift


【解决方案1】:

阅读截至 2019 年 3 月 1 日的 Discord 聊天后,这里有一个未解决的 fluent 问题:https://github.com/vapor/fluent-kit/issues/8

【讨论】:

    猜你喜欢
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2017-06-13
    • 2017-08-04
    • 2012-10-20
    • 1970-01-01
    相关资源
    最近更新 更多