JS Object strange behaviour when trying access Loopback related model query

人盡茶涼 提交于 2019-12-01 07:31:27

I just found issue 1425 which links to the following docs:

With Node.js API, you need to call toJSON() to convert the returned model instance with related items into a plain JSON object

Please note the relation properties […] points to a JavaScript function for the relation method.

So it seems you have to use

for (var i=0; i<roles.length; i++) {
    var x = roles[i].toJSON();
    cb(null, x.role.name === 'teamLeader'
             && x.groupId === context.modelId);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!