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
{{ message }}
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
Not all the properties of a model are sent via the request, some of them have to be calculated or fetched from DB and then use to create/save the model. Something like willCreate or willSave hook will be useful for these kind of situations.
The text was updated successfully, but these errors were encountered:
Your situation seems like one that will be common. What if the Request would be passed into the init(_ create: Create) and update(_ update: Update) methods? Then you could authenticate there (or do any other database lookup) and set the user id. Would that solve your problem?
@siemensikkema Thanks, that would solve the problem.
But I think it will cause some inconsistency in codes, as the Request would pass to init, all the code that should be written in Controller section, have to be written in Model, or some duplicate code will be present in Model.
Is it possible to append optional parameters to create and update methods?
Like this:
init(_ create:Post.Create, userId:userId)
or pass a dictionary like in NotificationCenter's userInfo
I have a simple
Post
modeluserId
property needs to be added after aUser
obtained fromtoken
. It can not be sent in request parameters. It was the code before usingSubmissions
Not all the properties of a model are sent via the request, some of them have to be calculated or fetched from DB and then use to create/save the model. Something like
willCreate
orwillSave
hook will be useful for these kind of situations.The text was updated successfully, but these errors were encountered: