How to update nested models in runtime?


Hi everyone, how are you?

I am new with adonis and i’m trying to build a simple app, but with some features.

My question is: How can i update a nested lucid model which belongs to a collection in runtime?

Ex of my code:

const User = use('App/Models/User')

let user = await User.with('carts').first()

let cart = user.carts[0] = 250

But the code above does not work, anyone can help me with the best way to do this?


Try getting relation, then update:

let cart = user.getRelated('carts').rows[0] = 250


Thanks, worked!