Best way to exclude virtual properties from patches #3221
Unanswered
ericuldall
asked this question in
Q&A
Replies: 1 comment 5 replies
-
You can exclude a property by returning export const uploadPatchResolver = resolve<Upload, HookContext>({
upload: async () => undefined
}) Which will always exclude the property. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I thought I had seem something in the docs addressing this use case but haven't been able to find it.
Here's the basic idea:
I have a service: User
That service has an uploadId that maps to the Uploads service and I want to create a virtual reference to the upload.
So User
{ _id, uploadId: Upload._id }
when queried becomesUser { _id, uploadId: Upload._id, upload: Upload {} }
The problem is if i'm working with the user object and then I send a patch, the upload property is now saved into mongo, which is not what should happen.
In feathers v4 I would use the
keep
hook to just define all the fields that should be allowed in the db, but now i'm wondering if there's a better way to do this with schemas and TypeBox.So far i've tried, adding
upload: Type.Readonly(Type.Ref(uploadsSchema))
but that didn't stop the record from getting inserted into mongo, so i'm not clear on what's the best way to handle this behavior.I would never want a virtual property to get inserted back into the db, so I feel like by default there should be some easy way to ensure that.
Beta Was this translation helpful? Give feedback.
All reactions