dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

hasone Relation, fail to getrelation table item. #674

Open liu946 opened 8 years ago

liu946 commented 8 years ago

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!