我的数据模型在TICKETS表和PLATES表之间有多对一的关系。我使用AWS Amplify GUI构建了这个模型,并将生成的源代码下载到我的Xcode项目中。对于我的数据模型中存在的关系,Xcode在Swift模式文件的PLATES表的这一行中抛出了几个错误:
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)
)
.hasMany行上的所有错误:
- 无法将类型“List?”的值转换为所需的参数类型“Model.Type”
- 示例成员“TICKETS”不能用于类型“PLATES”;是否要使用此类型值?
- 类型'List?'的值没有成员'keys'
基于Amplify文档,后端的GraphQL文件似乎结构正确:
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
}
我如何纠正这些错误?
1条答案
按热度按时间flvtvl501#
您的模型之间的关系是双向的吗(您使用@belongsTo指令吗)?如果是,不幸的是,根据文档,由于Swift,iOS不支持这种关系。
由于Swift语言的限制,双向“有一个”关系目前无法在iOS上表示。
希望能有所帮助