node-orm2
node-orm2 copied to clipboard
hasone Relation, fail to getrelation table item.
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.
I debugged the code and the program(in One.js) is into the last else.
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!