0

Im trying to figure out how can I manipulate my database using adonis repl. I understand models.User is what I should start with to manipulate Users table and I tried using models.User.query() and this function does exist but I cannot understand how to use this method because I was expecting it to bring back all the users but it seems to be bringing back an instance and configurations of model. my goal is to query users and then change the role of a certain user that I query with it's username.

somthing like this:

models.User.query().select().where('username','admin')

and then :

admin.role='editor'
w3bsite
  • 181
  • 1
  • 10

2 Answers2

1

As the other answer says, you forgot loadModels(). But you also need .first() to load one item, and the .select() is redundant if you're loading the whole model.

Then all you need to do is

const admin=await models.User.query().where('username','admin').first()
admin.role='editor'
await admin.save()
0
node ace repl
loadModels() >>> i think this is missing
let result = await models.User.query().select().where('username','admin')