Marc Rasmussen
Marc Rasmussen

Reputation: 20555

Loopback always returns results

So i have the following table:

external_user_has_survey_question_answer

enter image description here

This table has a belongsTo relation to the table:

external_user

enter image description here

Now i am trying to query data where member_id is equal to 3

  loopbackModels.findModel("external_user_has_survey_question_answer").find({
        include:
            {
                relation: 'external_user',
                scope: {
                    where: {member_id: member_id}
                }
            },
        where:{member_id: member_id}
    }, function (err,result) {
        cb(err,result);
    });

Problem is that no matter what I do (even if the member_id does not exist in my database) I get all results.

So my question is what have i done wrong?

Also here is my relation:

"relations": {
    "external_user": {
      "type": "belongsTo",
      "model": "external_user",
      "foreignKey": "external_user_id"
    }
  },

Upvotes: 0

Views: 59

Answers (1)

Sachin S
Sachin S

Reputation: 196

The query should be modified to

 loopbackModels.findModel("external_user_has_survey_question_answer").find({
    include:
        {
            relation: 'external_user',
            scope: {
                where: {member_id: member_id}
            }
        }
}, function (err,result) {
    cb(err,result);
});

And also all the results in external_user_has_survey_question_answer will be shown but the relation(key) external_user will be empty

Upvotes: 2

Related Questions