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
varSequelize=require('sequelize');varconfig=require(__dirname+'/config/database.json')['production'];varsequelize=newSequelize(config.database,config.username,config.password,config);varUser=sequelize.define("User",{login: {type : Sequelize.STRING,unique : true,allowNull : false,validate : {len : {args: [6,Infinity],msg: 'Login is too short'},isUnique : function(value,next){User.find({where: Sequelize.and({login: value},['id <> ?',this.id]),attributes: ['login']}).then(function(pf){if(pf)returnnext('User is taken!');next();}).catch(function(err){returnnext(err);});}}},pass: {type : Sequelize.STRING,allowNull : false,validate : {len : {args: [6,Infinity],msg: 'A senha é muito curta. min 6 characteres'}}},check_pass: {type : Sequelize.VIRTUAL,allowNull : false,validate : {match : function(val){if(val!==this.check_pass){thrownewError('Wrong pass.');}}}},});sequelize.sync().then(function(){vardata={id: 1,login: 'testing',pass: 'hashed_pass_here',check_pass: 'hashed_pass_here'};varwhere={id: 1}User.create(data).then(function(result){console.log('User created');// IT WORKSUser.update(data,{where: where}).then(function(result){console.log('User updated:',result);}).catch(function(err){console.log('Error updating user',err,err.stack);// IT GOES HERE});}).catch(function(err){console.log('Error creating user',err,err.stack);})});
Output:
Executing (default): SELECT "login" FROM "Users" AS "User" WHERE ("User"."login"='testing' AND id <> 1) LIMIT 1;
Executing (default): INSERT INTO "Users" ("id","login","pass","createdAt","updatedAt") VALUES (1,'testing','hashed_pass_here','2015-01-08 08:25:33.120 -03:00','2015-01-08 08:25:33.120 -03:00') RETURNING *;
User created
Executing (default): SELECT "login" FROM "Users" AS "User" WHERE ("User"."login"='testing' AND id <> 1) LIMIT 1;
Executing (default): UPDATE "Users" SET "id"=1,"login"='testing',"pass"='hashed_pass_here',"check_pass"='hashed_pass_here',"updatedAt"='2015-01-08 08:25:33.191-03:00' WHERE "id"=1
Error updating user { [SequelizeDatabaseError: coluna "check_pass" da relação "Users" não existe] // means Column "check_pass" of relation "Users" does not exists
name: 'SequelizeDatabaseError',
message: 'coluna "check_pass" da relação "Users" não existe', // means Column "check_pass" of relation "Users" does not exists
parent:
{ [error: coluna "check_pass" da relação "Users" não existe] // means Column "check_pass" of relation "Users" does not exists
name: 'error',
length: 133,
severity: 'ERRO',
code: '42703',
detail: undefined,
hint: undefined,
position: '71',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'src\\backend\\parser\\analyze.c',
line: '2001',
routine: 'transformUpdateStmt',
sql: 'UPDATE "Users" SET "id"=1,"login"=\'testing\',"pass"=\'hashed_pass_here\',"check_pass"=\'hashed_pass_here\',"updatedAt"=\'2015-01-08 08:25:33.191 -03:00\' WHERE "id"=1' },
original:
{ [error: coluna "check_pass" da relação "Users" não existe] // means Column "check_pass" of relation "Users" does not exists
name: 'error',
length: 133,
severity: 'ERRO',
code: '42703',
detail: undefined,
hint: undefined,
position: '71',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'src\\backend\\parser\\analyze.c',
line: '2001',
routine: 'transformUpdateStmt',
sql: 'UPDATE "Users" SET "id"=1,"login"=\'testing\',"pass"=\'hashed_pass_here\',"check_pass"=\'hashed_pass_here\',"updatedAt"=\'2015-01-08 08:25:33.191 -03:00\' WHERE "id"=1' },
sql: 'UPDATE "Users" SET "id"=1,"login"=\'testing\',"pass"=\'hashed_pass_here\',"check_pass"=\'hashed_pass_here\',"updatedAt"=\'2015-01-08 08:25:33.191 -03:00\' WHERE "id"=1' }
SequelizeDatabaseError: coluna "check_pass" da relação "Users" não existe // means Column "check_pass" of relation "Users" does not exists
at module.exports.Query.formatError (C:\Users\Guilherme\Documents\node\iapo1\node_modules\sequelize\lib\dialects\postgres\query.js:301:16)
at null.<anonymous> (C:\Users\Guilherme\Documents\node\iapo1\node_modules\sequelize\lib\dialects\postgres\query.js:64:21)
at emit (events.js:95:17)
at Query.handleError (C:\Users\Guilherme\Documents\node\iapo1\node_modules\pg\lib\query.js:99:8)
at null.<anonymous> (C:\Users\Guilherme\Documents\node\iapo1\node_modules\pg\lib\client.js:166:26)
at emit (events.js:95:17)
at Socket.<anonymous> (C:\Users\Guilherme\Documents\node\iapo1\node_modules\pg\lib\connection.js:109:12)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
It validates to check if pass is equal check_pass and insert, it does the validation again on update but it doesn't remove check_field before trying to update it.
The text was updated successfully, but these errors were encountered:
Hi, I have this code
Output:
It validates to check if pass is equal check_pass and insert, it does the validation again on update but it doesn't remove check_field before trying to update it.
The text was updated successfully, but these errors were encountered: