My data model has a many to one relationship between the TICKETS table and the PLATES table. I built the model out using the AWS Amplify GUI and pulled down the source code generated into my Xcode project. For the relationships that exist in my data model, Xcode throws several errors on this line of the Swift schema file for the PLATES table:
model.fields(
.id(),
.field(pLATES.plateState, is: .optional, ofType: .string),
.field(pLATES.plateNumber, is: .optional, ofType: .string),
.field(pLATES.vehicleMake, is: .optional, ofType: .string),
.field(pLATES.vehicleModel, is: .optional, ofType: .string),
.field(pLATES.vehicleYear, is: .optional, ofType: .int),
.field(pLATES.vehicleColor, is: .optional, ofType: .string),
.hasMany(pLATES.TICKETS, is: .optional, ofType: TICKETS.self, associatedWith: TICKETS.keys.platesID),
.field(pLATES.usersID, is: .optional, ofType: .string),
.field(pLATES.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
.field(pLATES.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
)
Errors all on the .hasMany line:
- Cannot convert value of type 'List?' to expected argument type 'Model.Type'
- Instance member 'TICKETS' cannot be used on type 'PLATES'; did you mean to use a value of this type instead?
- Value of type 'List?' has no member 'keys'
The GraphQL file on the backend appears to be structured correctly based on the Amplify documentation:
type TICKETS @model @auth(rules: [{allow: public}]) @key(name: "byPLATES", fields: ["platesID"]) {
id: ID!
ticketID: Int
reasonCode: Int
ticketDateTime: AWSDateTime
ticketLocationLong: Float
ticketLocationLat: Float
platesID: ID
USERS: USERS @connection
}
type PLATES @model @auth(rules: [{allow: public}]) @key(name: "byUSERS", fields: ["usersID"]) {
id: ID!
plateState: String
plateNumber: String
vehicleMake: String
vehicleModel: String
vehicleYear: Int
vehicleColor: String
TICKETS: [TICKETS] @connection(keyName: "byPLATES", fields: ["id"])
usersID: ID
}
How can I remedy those errors?