Support for Calculated Attributes dependent on related models
I was disappointed with the lack of support for calculated attributes dependent on related models and wrote a plugin to implement that functionality. I wanted to bring that plugin to the attention of the developers in the event that they were interested in implementing that functionality in future releases. I'm confident that there are others out there who would find the functionality useful as well.
Would be great to have this in Loopback.
@michael-lumley would you mind creating a pull request with your plugin?
@smehrbrodt I'm a little hesitant to do that, for a couple of reasons - first and foremost, I'm a lawyer by training, programming is just a hobby for me, so I'm not totally confident that the plugin won't break under certain use cases. Second, I don't want to step on the toes of the project leads - I don't want to muck up the project with some unconventional code. Finally, the code is available at the link above to those who'd like to implement it for themselves, and by including it in a module or a bootscript, you can make sure that it doesn't get overwritten by subsequent releases of the main loopback project.
Thanks for the thought, though!
Would definitely use this if it were merged.
+1
@michael-lumley Feel free to submit a PR, if anything looks odd, we'll give you feedback. ;)
:+1: Would be a great feature.
I just figured out that this can actually be solved pretty conveniently with operational hooks. I posted a sample here: https://stackoverflow.com/questions/25438663/dynamic-properties-or-aggregate-functions-in-loopback-models/32285839#32285839
From my point of view this solves this issue and it can therefore be closed.
You can also use our computed property mixin - https://github.com/fullcube/loopback-ds-computed-mixin
@michael-lumley: looks like you can use the two work arounds above or open a PR for us to merge (to speed up the process). Going to close, please re-open if you still require this.