Skip to content Skip to sidebar Skip to footer

JS Object Strange Behaviour When Trying Access Loopback Related Model Query

I am working with the Loopback Framework, doing a web project. But I think that the question that I am exposing here has less to do with this, but with general Javascript / Node.JS

Solution 1:

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);
}

Post a Comment for "JS Object Strange Behaviour When Trying Access Loopback Related Model Query"