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 trying to figure out how to dynamically build associations, and I'm a bit confused about the API and what the correct way to handle this is.
My primary use case is we have a complex data model where we need to call multiple traits to set up a variety of associations. These traits can't use associations() though, because we need to generate the association in the context of a specific record (i.e. we need to be able to set foreign keys).
I'm running into a few issues that either may be my misunderstanding and/or possible bugs:
The different lifecycle hooks are confusing. From the documentation, onCreate and afterCreate seem to be specifically for async side-effects. But out of the 3 lifecycle hooks, only onCreate seems to update the factory result from the hook's return value. Is this the intended result / use case? It's just awkward to have to await a factory when I'm not using any async behavior.
Chaining traits doesn't seem to work correctly. If I have a factory with multiple traits that update associations via onCreate, only the last called trait will stick. This seems like it is either a bug or I'm not using the hook as intended. I missed in the documentation that onCreate can only be defined once. Given this limitation, this seems like a poor option for my use case.
Is there a way to use composable traits that update the shape of the object?
Thanks!
The text was updated successfully, but these errors were encountered:
I'm trying to figure out how to dynamically build associations, and I'm a bit confused about the API and what the correct way to handle this is.
My primary use case is we have a complex data model where we need to call multiple traits to set up a variety of associations. These traits can't use
associations()
though, because we need to generate the association in the context of a specific record (i.e. we need to be able to set foreign keys).This is an example that I have been working with:
I'm running into a few issues that either may be my misunderstanding and/or possible bugs:
The different lifecycle hooks are confusing. From the documentation,
onCreate
andafterCreate
seem to be specifically for async side-effects. But out of the 3 lifecycle hooks, onlyonCreate
seems to update the factory result from the hook's return value. Is this the intended result / use case? It's just awkward to have toawait
a factory when I'm not using any async behavior.Chaining traits doesn't seem to work correctly. If I have a factory with multiple traits that update associations viaI missed in the documentation thatonCreate
, only the last called trait will stick. This seems like it is either a bug or I'm not using the hook as intended.onCreate
can only be defined once. Given this limitation, this seems like a poor option for my use case.Is there a way to use composable traits that update the shape of the object?
Thanks!
The text was updated successfully, but these errors were encountered: