Replies: 1 comment
-
It seems that the issue might be caused by the recalculation of relationships with other entities when executing the I've encountered a similar problem: in my case, the models had many relationships, and every time I executed the Eventually, I arrived at a solution: if the data collection was large, I handled adding, updating, and deleting entity instances through Pinia ORM but performed data reads directly from an array stored in export const useAchievementsStore = defineStore('achievementsStore', {
state() {
return {
achievements: []
}
},
getters: {
repository() {
return useRepo(EventParticipation);
},
getAchievementsWithRelations() {
// return this.repository.withAllRecursive().get()
return this.achievements
},
},
actions: {
async fetchAchievements() {
try {
this.repository.flush()
const response = await apiClient.get("EventParticipation/GetAchievements")
this.repository.save(response.data)
this.achievements = response.data
} catch (error) {
console.error("Error fetching achievements:", error)
}
},
async addAchievement(achievementData) {
try {
const response = await apiClient.post("EventParticipation/Create", achievementData)
this.repository.save(response.data)
} catch (error) {
console.error('Error adding achievement:', error)
throw error
}
},
async editAchievement(id, achievementData) {
try {
const response = await apiClient.put(`EventParticipation/Edit/${id}`, achievementData)
this.repository.save(response.data)
} catch (error) {
console.error('Error editing achievement:', error)
throw error
}
},
async deleteAchievement(id) {
try {
await apiClient.post('EventParticipation/Delete', { id })
this.repository.destroy(id)
} catch (error) {
console.error('Error deleting achievement:', error)
throw error
}
},
async getAchievementById(id) {
return await this.repository.withAllRecursive().find(id)
}
}
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
This might be a problem on my end but im at the end of my ideas.. I really would like to understand better whether there might be a reason why Pinia ORM plays a part in this problem.
I have a situation where I have an object Building, and I do a save action like such:
useRepo(Building).save({ id: 33, length: 200 })
In another component (A vue component that represents the building) I have a computed defined like this:
const building = computed<Building | null>(() =>
useRepo(Building).find(props.id),
{
onTrigger(e) {
console.log("Building computed trigger ", props.id)
}
})
My issue is that on saving, the computed recalculation is triggered for all buildings. Note that it is correct that those computeds are activated/tracked, but the onTrigger should not be firing since nothing was updated on all other buildings. This is an issue for me because the query in my code is much more complicated than just a find() call. I replaced it here for simplicity (and verified that the issue does occur this way)
When I look at e (the onTrigger argument), it strikes me that both newValue and oldValue contain an array with all buildings, and the target contains the whole store..
It should be noted that Building is a subclass of another class which is a subclass of Model. that other class adds a few fields to the store object that pinia orm uses.
I have checked with hooks that only 1 building is saved (only 1 hook is triggered)
Any pointers in some kind of direction would be welcome!
Beta Was this translation helpful? Give feedback.
All reactions