Model JSON default scope declaration breaks update
Assuming a model definition like so:
(test-model.json)
{
"name": "TestModel",
"plural": "TestModels",
"base": "PersistedModel",
"idInjection": false,
"mysql": {
"schema": "test_schema",
"table": "test_model"
},
"properties": {
"id": {
"type": "Number",
"id": true,
"required": true,
"index": true,
"length": null,
"precision": 11,
"scale": 0,
"mysql": {
"columnName": "id",
"dataType": "int",
"dataLength": null,
"dataPrecision": 11,
"dataScale": 0,
"nullable": "N"
},
"_selectable": true
},
"name": {
"type": "String",
"required": true,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "name",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": true
},
"deleted": {
"type": "Boolean",
"required": true,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "deleted",
"dataType": "tinyint",
"dataLength": null,
"dataPrecision": 1,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
}
},
"scope": {
"where": {
"deleted": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
and having overridden the TestModel.deleteById method:
(test-model.js)
module.exports = function(TestModel) {
TestModel.on('attached', function() {
TestModel.deleteById = function(id, cb) {
console.log('Overridden TestModel.deleteById');
TestModel.update({'id': id}, {'deleted': true}, cb);
}
});
};
the query produced is the following (datasource "debug": true):
--> ComQueryPacket
{ command: 3,
sql: 'UPDATE `test_model` SET `deleted` = 0 WHERE (`id` = 1) AND (`deleted` = 0)' }
Seems that the default scope column "deleted" value is assigned as the SET value of the "deleted" param.
Note that if one is to remove the default scope declaration from the .json file, the update works as expected.
Regards.
dao.js

utils.js

// setScopeValuesFromWhere(data, scope.where, this); works
Solution server.js before boot

Can't loopback just make a feature to set a scope option to include or exclude specific calls
LoopBack 3 has reached end of life, we are not going to add any new features.
@bajtos Also LoopBack 4 has the same problem, the scope interferes everywhere on every crud operation
According to the loopback overview logic it shouldn't

Anyway good luck, i extended to my models to another repository that extended to default crud repository, that way i could just remove the scope completely and override the field i needed on every crud operation method.