Collection BeforeChange Hook - acess to auto-generated ID #1962
-
Hi, Because right now, imagine the situation:
Users{
userId: <payloadGenerated>
bankAccountId: <idFromBankCollection>
}
BankAccount{
bankAccoutnId: <payloadGenerated>
owner: <idFromUserCollection>
} For that case, I need two hooks:
That is because in Maybe someone has better idea how to proceed with such cases? Or should I avoid bi-directional relations, and simple embedding them on users? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@dawidmachon you're right in that if the operation is
This will work for that initial connection but updates on either end of the relationship will also need to be wired in—and this may lead to infinite loops. There are ways around this, like maintaining a hidden |
Beta Was this translation helpful? Give feedback.
@dawidmachon you're right in that if the operation is
create
, there is not yet an ID to use. Your solution looks fine to me, does it work? Just to sum it up:bankAccountId
to the userowner
with theiruserId
This will work for that initial connection but updates on either end of the relationship will also need to be wired in—and this may lead to infinite loops. There are ways around this, like maintaining a hidden
skipHooks
field on the collection, I've done something similar to this in our Stripe plugin. Others have run into this same need, though, and there'…