I am trying to create a new record for a model and there are fields I need to save later after the model is created.
I have the code like this
let new_model = await Model.create({ name, type}).fetch();
new_model.content = 'abc';
new_model.save();
TypeError: new_model.save is not a function
I googled, it doesn't seem like sailsjs
can be done this way so I guess I have to use the update
or updateOne
by sails. But the thing is, name,type
fields are not unique and will not be so using update
will actually turn into update for ALL records. updateOne
will give me errors saying there's more than one record though
Does anyone has any suggestions on what can be done here?
One other option I can think of is doing something like this with updateOne
let new_model = await Model.create({ name, type}).fetch();
// getting your content here or do something else
const content = 'abc';
new_model = await Model.updateOne({ id:new_model.id}).set({content});