首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >有关系的‘Model`类是什么样子的?

有关系的‘Model`类是什么样子的?
EN

Stack Overflow用户
提问于 2016-11-27 11:14:56
回答 1查看 177关注 0票数 2

使用Vapor,我想存储与孩子的关系。我还没有找到这个类应该是什么样子的任何示例,我只是在猜测该做什么。有人能提供一个与其他Model对象列表有关系的类的示例吗?

代码语言:javascript
复制
import Vapor
import Fluent
import Foundation

final class Store: Model {

    // MARK: - Model
    var id: Node?
    var exists: Bool = false
    var locationIDs: [Node] = [] // No idea if this is right

    var name: String

    init(name: String, locationIDs: [Node] = []) {
        self.id = nil
        self.name = name
        self.locationIDs = locationIDs
    }

    init(node: Node, in context: Context) throws {
        id = try node.extract("id")
        name = try node.extract("name")
//      ???
    }

    func makeNode(context: Context) throws -> Node {
        return try Node(node: [
            "id": id,
            "name": name
//          ???
        ])
    }

    static func prepare(_ database: Database) throws {
        try database.create( "stores" ) { creator in
            creator.id()
            creator.string("name")
//            creator.id("", optional: false) // ???
        }
    }

    static func revert(_ database: Database) throws {
        try database.delete("stores")
    }

}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40825433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档