You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm attempting to create a generic model that relates a set of two identical models (i.e. a user relationship) - the purpose of putting it in an extension is it would handle some basics for me like checking deletions, indexing, etc
It looks like this:
abstract model RelationshipBaseWithUsers extends Base {
requesterId String @map("requester_id")
recipientId String @map("recipient_id")
requester User @relation("RelationshipsSent", fields: [requesterId], references: [id], onDelete: Cascade)
recipient User @relation("RelationshipsReceived", fields: [recipientId], references: [id], onDelete: Cascade)
// deny all access if either user is deleted or banned
@@deny('all', requester.deletedAt != null || (requester.banned != false && requester.banned != null))
@@deny('all', recipient.deletedAt != null || (recipient.banned != false && recipient.banned != null))
// deny all access if either user is blocked
@@deny('all', requester.sentBlocks?[this.recipient == recipient] || recipient.sentBlocks?[this.requester == requester])
@@index([requesterId, recipientId, deletedAt], map: "requester_block_reverse_idx")
@@index([recipientId, requesterId, deletedAt], map: "recipient_block_reverse_idx")
}
Unfortunately, using this more than once will break, as the @relation and index maps would cause duplicates, and thus it's invalid.
Instead, I would love to see something like:
abstract model RelationshipBaseWithUsers(arg1, arg2, arg3, arg4) extends Base {
requesterId String @map("requester_id")
recipientId String @map("recipient_id")
requester User @relation(arg1, fields: [requesterId], references: [id], onDelete: Cascade)
recipient User @relation(arg2, fields: [recipientId], references: [id], onDelete: Cascade)
// deny all access if either user is deleted or banned
@@deny('all', requester.deletedAt != null || (requester.banned != false && requester.banned != null))
@@deny('all', recipient.deletedAt != null || (recipient.banned != false && recipient.banned != null))
// deny all access if either user is blocked
@@deny('all', requester.sentBlocks?[this.recipient == recipient] || recipient.sentBlocks?[this.requester == requester])
@@index([requesterId, recipientId, deletedAt], map: arg3)
@@index([recipientId, requesterId, deletedAt], map: arg4)
}
Or potentially even:
abstract model RelationshipBaseWithUsers(arg) extends Base {
requesterId String @map("requester_id")
recipientId String @map("recipient_id")
requester User @relation(arg + "Requested", fields: [requesterId], references: [id], onDelete: Cascade)
recipient User @relation(arg + "Received", fields: [recipientId], references: [id], onDelete: Cascade)
// deny all access if either user is deleted or banned
@@deny('all', requester.deletedAt != null || (requester.banned != false && requester.banned != null))
@@deny('all', recipient.deletedAt != null || (recipient.banned != false && recipient.banned != null))
// deny all access if either user is blocked
@@deny('all', requester.sentBlocks?[this.recipient == recipient] || recipient.sentBlocks?[this.requester == requester])
@@index([requesterId, recipientId, deletedAt], map: arg + "_idx")
@@index([recipientId, requesterId, deletedAt], map: arg + "_reversed_idx")
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm attempting to create a generic model that relates a set of two identical models (i.e. a user relationship) - the purpose of putting it in an extension is it would handle some basics for me like checking deletions, indexing, etc
It looks like this:
Unfortunately, using this more than once will break, as the @relation and index maps would cause duplicates, and thus it's invalid.
Instead, I would love to see something like:
Or potentially even:
Beta Was this translation helpful? Give feedback.
All reactions