Replies: 3 comments
-
Hi @cchris14 , I think that it is not a good idea to make multiple API calls because you cannot guarantee the consistency of the data. For example, if you make 3 requests against the API and the third one fails (for whatever reason), then you would have to roll back the previous two requests in some way. Search for "Fillable Relations" on GitHub - that might help you. |
Beta Was this translation helpful? Give feedback.
-
I'll be more specific about this question. Basically its a best practice question: if i cant create an user without related tables should I include them in a hook and create the related data with the initial API call or make 2 api requests and risks to have an user without its required related data ? |
Beta Was this translation helpful? Give feedback.
-
It depends on the business use-case you are trying to cover. If creation of one entity does not depend on the other (meaning, if one entity is created, but the other one is not, the business logic of an app is not broken), then having two separate API resources / controllers is the way to go in the current state of what Orion provides. However, if creation of one entity without another would mean an incomplete data stored in the database and the entity would not function correctly without the other one, then the hooks is the way to go to ensure that both entities are persisted. |
Beta Was this translation helpful? Give feedback.
-
I have a User Model link with Sites and Role.
On save to my User Model, is it better to use AfterSave from hooks or make 2 others call API to assign the role of my user and save his sites ?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions