You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At this point I'm really confused how it should work correctly.
I'm just at the beginning. Using Models on its own are easy to understand, but when I try to add relationships I don't get anywhere.
Here is my example:
// Parent Model - Device.js:import{Model}from'@vuex-orm/core'importUptimefrom'@/models/Uptime'exportdefaultclassDeviceextendsModel{staticentity='devices'staticprimaryKey=['id']staticfields(){return{id: this.uid(),name: this.string(''),uptime: this.hasOne(Uptime,'device_id')}}}
// Child Model - Uptime.js:import{Model}from'@vuex-orm/core'exportdefaultclassUptimeextendsModel{staticentity='uptimes'staticprimaryKey=['id']staticfields(){return{id: this.uid(),device_id: this.string(null),uptime: this.string('').nullable()}}}
// My component.vue where I try to update my uptime state:
...
methods: {getUptime(){consturl='/device/uptime'this.loading=truethis.$axios.get(url).then(async(res)=>{constuptime=res.data.data.uptime// <- Uptime is just a string here// Updating Device with new uptimeconstcheck=awaitDevice.update({<--Hereismyproblem// where: this.getCurrentDeviceId, // does not work, because not allowed for relationshipsdata: {id: this.getCurrentDeviceId,uptime: { uptime }}})console.log('check:',check)})...}}
At this point I think its in a very simple state.
I want to add more models like Uptime to my parent model Device in the future.
Many thanks in advance. :)
Edit: Added the way how I register vuex-orm in nuxt.
The text was updated successfully, but these errors were encountered:
You don't need to update the Device record - just update the proper Uptime record with the appropriate device_id. Btw since it is a one to one relationship, you might not even need 2 models and just store the uptime in the Device model. Alternatively, you don't need 'id' and 'device_id' on the Uptime model - you can make 'device_id' the primary key so that getting the apropriate Utime for a Device is easier.
Thank you so much for the help. :)
I think I tried that already... but I will try it again.
My example is just for two Models. Device as main and Uptime as a secondary.
My plan for the future is to have multiple models in a relationship with Device (Models like: CPU, Diskspace, Memory, Processes and more...).
In the future, I would like to have the possibility to create several devices (I have only one device right now) and assign the corresponding values to each device.
First of all, thanks for this amazing project. :)
Secondly... yes... I searched a lot and I tried to solve my problem with the docs:
At this point I'm really confused how it should work correctly.
I'm just at the beginning. Using Models on its own are easy to understand, but when I try to add relationships I don't get anywhere.
Here is my example:
This is where my real problem hides.
At this point I think its in a very simple state.
I want to add more models like
Uptime
to my parent modelDevice
in the future.Many thanks in advance. :)
Edit: Added the way how I register vuex-orm in nuxt.
The text was updated successfully, but these errors were encountered: