-
Hi, I might be missing something obvious. One reason im using pinia orm is to make sure data is not recomputed when nothing changed. In VuexOrm or Vuex (or Pinia?) I would use Getters for this, which, as I understand, are basically computed references. However I can't quite get this to work properly with Pinia ORM. I have a model called Location, which needs to keep a currentId for the currently selected record. I added a static function to the model like this:
This function 'current()' I am using all over the place, in all kinds of components. It is not uncommon for this function to be called 10+ times during 1 page load. Within the components I call the function like this:
What I see is that the query is ran for every component. How do I avoid this? Especially the hydration of models adds up over time Maybe what I want is that the pinia orm store keeps the computed reference that I can then use? I tried using the cache (in the current call, and then clearing it in a saving hook), but it doesnt play nice with computed references. when the cache is cleared, the computed property doesnt update. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I have something of a solution maybe? But its not working yet. Would appreciate feedback. I have the below in the model:
The above doesnt work because it doesnt return a valid instance (pinia orm did not work its magic on it) One complicating factor is that in the getter I dont have access to the Model directly. All models are inherited from a single model (Called MyModel) . This is so I dont have to repeat all the logic for currents (and a few other things). However because of this, this doesnt work in the getter: useRepo(MyModel).find(this.currentId) Ideally I would be able to use Location in the MyModel getter, but I can't figure out how to do that. The DataStore doesnt have a reference to Location, as far as I can see. |
Beta Was this translation helpful? Give feedback.
I have something of a solution maybe? But its not working yet. Would appreciate feedback.
I have the below in the model:
The above doesnt work because it doesnt return a valid instance (pinia orm did not work its magic on it)
One complicating factor is that in the getter I dont have access to the Model directly. All models are inherited from a single model (Called MyModel) . This is so I dont have to repeat all the logic for currents (…