ml-archive/submissions

Example doesn't compile

Closed this issue · 2 comments

Your example doesn't seem to actually compile. I took my Client class, which implements PostgreSQLModel, Content, and Parameter and added this code:

extension Client: Submittable {
    struct Create: Decodable {
        let name: String
    }

    struct Submission: SubmissionType {
        let name: String?
    }

    convenience init(_ create: Create) {
        self.init(name: create.name)
    }

    func update(_ submission: Submission) {
        if let name = submission.name {
            self.name = name
        }
    }
}

extension Client.Submission {
    func fieldEntries() throws -> [FieldEntry] {
        return try [
            makeFieldEntry(keyPath: \Client.name, label: "Client Name", validators: [.count(5...)], isOptional: false)
        ]
    }

    init(_ client: Client?) {
        name = client?.name
    }
}

I'm getting this compiler error:

Ambiguous reference to member '...'

@grosch In the line where you make your "name" field entry, you have \Client.name but it should be \Client.Submission.name or simply \.name. Let me know if that helps!

Thanks, that was it.