Hey folks. Consider the code below. It represents an explicit many to many relationship. The UserCommunicationChannelLink
contains attributes which do not belong neither in User
nor in CommunicationChannel
. Consequently, I create a Link
table, with manyToOne
relations, meaning
the foreignKey
are on the many side (the link table).
const collectionId = 'UserCommunicationChannelLink'
await db.createRelationshipAttribute(
db.id,
collectionID,
'User',
'manyToOne',
false,
'user',
undefined,
'restrict',
);
await db.createRelationshipAttribute(
db.id,
collectionID,
'CommunicationChannel',
'manyToOne',
false,
'channel',
undefined,
'restrict',
);
The idea is that a User
can have many CommunicationChannels
and, each CommunicationChannel
may exist in more than one user. However, each pair of <userId, communicationChannelid>
must be unique in the Link
table.
When I execute this migration, I get a failure on createRelationshipAttribute
;
Error: Cannot create an index for a relationship attribute: user
Is it impossible to create a uniqueness index on two foreign keys?
Recommended threads
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...
- What Query's are valid for GetDocument?
Documentation shows that Queries are valid here, but doesn't explain which queries are valid. At first I presumed this to be a bug, but before creating a githu...
- Appwrite exception: user_unauthorized, t...
After refreshing the app it is working perfectly