How to do non-persisted computed values? #5411
Unanswered
NickEastNL
asked this question in
Q&A
Replies: 1 comment 4 replies
-
You can use getters, just add https://mikro-orm.io/docs/defining-entities#virtual-properties The |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to compute certain values based on stored properties before sending the data to the client. Usually I would use getters, which I assumed is what virtual properties were for. But they don't "exist" after fetching an item from the database. The only way I see them is when I use
wrap(entity).toJSON()
. But what if I need to find more than one entity? It doesn't seem right to first fetch the entities, then iterate through them to wrap each one up before sending them out.The "fullName" example given in the docs is very unclear. It's the kind of effect I want, but it only seems to work after creating an entity, rather than fetching them. Then there's the matter of have to make the getters "optional" as otherwise
create
will complain they're missing.So is there a way to have entities carry computed values directly when fetching them? Or do I have to wrap them one by one?
Beta Was this translation helpful? Give feedback.
All reactions