node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

hasone Relation, fail to getrelation table item.

Open liu946 opened this issue 9 years ago • 0 comments

node v0.12.4

model file

var tb = require('../../field/biaozhixinggouzhuwu')
module.exports = function (orm, db) {
  var Comment = db.define('biaozhixinggouzhuwu', tb.backendfield(),{
    methods: {

    }
  });
  Comment.getall = function (cb) {
    return this.all({},{only:["id","LeiXing" ]},function(err,items){
      for(var i in items ){
        var item = items[i];
        item.getCunzhen(function(err,cunzhen){ // this callback function's argument "cunzhen" is undefined
          item['SuoShuCunZhen'] = (cunzhen == undefined ? null: cunzhen["CZJBXXCunZhenMingChen"] );
        });
      }
      cb(items)
    });
  };
  Comment.hasOne("cunzhen", db.models['cunzhen']);
};

the callback function's argument "cunzhen" is undefined but it really has a "cunzhen" in the database tables. 2015-10-25 12 57 16 2015-10-25 12 57 28

I debugged the code and the program(in One.js) is into the last else. 2015-10-25 12 59 07

The column you generate is "cunzhen_id" but second last condition find that "cunzhen" is not a value in the Instance. I dont know if this has relationship to the problem.

thanks!

liu946 avatar Oct 24 '15 17:10 liu946