- Newest
- Most votes
- Most comments
Based on your schema, you have a one-to-one relationship between the Booking, Client, and Tutor models. When you try to delete a Booking, it's possible that it fails due to the relationships with the Client and Tutor models.
To resolve this issue, you can modify your schema to use the @connection directive instead of @hasOne. This will help you establish a one-to-one relationship between the models without causing errors when deleting related items.
Update your schema as follows:
type Client @model @auth(rules: [{allow: groups, groups: ["admins"], operations: [read, create, update, delete]}, {allow: private}, {allow: public, operations: [read]}]) {
id: ID!
email: AWSEmail!
firstName: String!
lastName: String!
authToken: String!
phone: AWSPhone
credits: Float!
Students: [Student] @hasMany(indexName: "byClient", fields: ["id"])
booking: Booking @connection
}
type Tutor @model @auth(rules: [{allow: public, operations: [read, create, update]}, {allow: groups, groups: ["admins"], operations: [read, create, update, delete]}, {allow: groups, groups: ["tutors"], operations: [read, update, delete, create]}, {allow: private}]) {
id: ID!
email: AWSEmail!
firstName: String!
lastName: String!
authToken: String!
phone: AWSPhone
isRemote: Boolean!
isInPerson: Boolean!
hourlyRate: Float!
grade: String!
isSearchable: Boolean!
isActive: Boolean!
location: String
resumeUrl: String
transcriptUrl: String
photoUrl: String
bio: String
subjects: [String]
schoolAttended: String
booking: Booking @connection
}
type Booking @model @auth(rules: [{allow: private}]) {
id: ID!
startDateTime: AWSDateTime!
duration: Int!
bookingCode: String!
amount: Float!
discount: Float!
clientNotes: String
tutorNotes: String
tutorPaid: Boolean!
clientPaid: Boolean!
resources: String
studentName: String
tutorRating: Int
clientRating: Int
bookingType: String
tutorPayAmount: Float
tip: Float
transactionId: String
tutorMileage: Float
meetingUrl: AWSURL
hwFiles: [String]
resourceFiles: [String]
meetingInstructions: String
sessionTaught: Boolean!
clientId: ID! @hasOne
tutorId: ID! @hasOne
}
Based on your schema, you have a one-to-one relationship between the Booking, Client, and Tutor models. When you try to delete a Booking, it's possible that it fails due to the relationships with the Client and Tutor models.
To resolve this issue, you can modify your schema to use the @connection directive instead of @hasOne. This will help you establish a one-to-one relationship between the models without causing errors when deleting related items.
Update your schema as follows:
graphql Copy code type Client @model @auth(rules: [{allow: groups, groups: ["admins"], operations: [read, create, update, delete]}, {allow: private}, {allow: public, operations: [read]}]) { id: ID! email: AWSEmail! firstName: String! lastName: String! authToken: String! phone: AWSPhone credits: Float! Students: [Student] @hasMany(indexName: "byClient", fields: ["id"]) booking: Booking @connection }
type Tutor @model @auth(rules: [{allow: public, operations: [read, create, update]}, {allow: groups, groups: ["admins"], operations: [read, create, update, delete]}, {allow: groups, groups: ["tutors"], operations: [read, update, delete, create]}, {allow: private}]) { id: ID! email: AWSEmail! firstName: String! lastName: String! authToken: String! phone: AWSPhone isRemote: Boolean! isInPerson: Boolean! hourlyRate: Float! grade: String! isSearchable: Boolean! isActive: Boolean! location: String resumeUrl: String transcriptUrl: String photoUrl: String bio: String subjects: [String] schoolAttended: String booking: Booking @connection }
type Booking @model @auth(rules: [{allow: private}]) { id: ID! startDateTime: AWSDateTime! duration: Int! bookingCode: String! amount: Float! discount: Float! clientNotes: String tutorNotes: String tutorPaid: Boolean! clientPaid: Boolean! resources: String studentName: String tutorRating: Int clientRating: Int bookingType: String tutorPayAmount: Float tip: Float transactionId: String tutorMileage: Float meetingUrl: AWSURL hwFiles: [String] resourceFiles: [String] meetingInstructions: String sessionTaught: Boolean! clientId: ID! @hasOne tutorId: ID! @hasOne } After updating your schema, you need to run amplify push to apply the changes to your backend.
Now, when you delete a Booking, it should no longer fail due to the relationships with the Client and Tutor models. Make sure to update your queries and mutations in your code to reflect the new schema changes.
Relevant content
- asked 2 years ago
- asked 7 months ago
- asked 2 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago