0

问题:我正在开发一个 Android 应用程序,它使用 mysql 后端的 node orm 与 nodejs REST 服务器交互。在我的服务器上,我具有基于电子邮件验证对用户进行身份验证的功能。一旦验证成功,节点 orm 会获取用户对象,更改已验证的列值并将其保存回来。但是,执行后更改并未反映在数据库中。只有当我们再次运行相同的代码时,它才会反映在数据库中

代码

    exports.activateEmail = function(email, callback) {
    log.info('In verifyEmailDao.js, activateEmail module');
    var db = connectionObj.getConnection();
    var Candidate = db.models.jobseeker_id;

  Candidate.find({email : email}, function(err,candidate){
    if(err){
      log.info('cannot find account with email to activate', email);
      callback(false, null);
    }
    else {
      candidate[0].verified = true;
        log.info('candidate email now activated.! status is', candidate[0].verified);
      candidate[0].save(function(error){
        log.info('Email verified any errors?', error);
        callback(true, candidate[0].id);
      });
       }
   });
}

编辑1:

jobseeker_id.js (node-orm 模型)

var orm = require('orm');
module.exports = function(db){
  console.log('coming inside candidateId.js');
  var JobSeekerId = db.define('jobseeker_id', {
    id : {type:'serial' , key:true},
    first_name : String,
    last_name : String,
    email : String,
    password : String,
    verified : Boolean
  },{
    validations : {
      email : orm.enforce.unique("Already registered")
    }
  });
}

服务器日志:

{"name":"test-app" "msg":"In verifyEmailDao.js, activateEmail module"}
{"name":"test-app","msg":"candidate email now activated.! status is true"}
{"name":"test-app","msg":"Email verified any errors? null"}
{"name":"test-app","msg":"Email sucessfully activated. Now deleting the entry from verify email link table for candidate id 30}
{"name":"test-app","msg":"In verifyEmailDao.js, deleteRandomLink module"}
{"name":"test-app","msg":"error is---> null"}
{"name":"test-app","msg":"Entry deleted from verify email table as email is activated"}

第二次执行代码时,日志不会有任何变化,但会反映db中的变化!

4

1 回答 1

0

经过两天的地狱,我终于通过db.settings.set('instance.cache', false)在 db 配置文件中添加一条语句来解决这个问题。虽然我没有清楚地理解如何通过将缓存设置为 false 来解决数据库更新问题,但这确实成功了!

于 2016-04-18T16:18:39.303 回答