1
votes

So i have a model that has the following relationship:

"relations": {
    "member": {
        "type": "belongsTo",
        "model": "Member",
        "foreignKey": "member_id"
    }
},

Now Member has a field called email.

I now want to query all results where the email is set to a specific value:

{
    "include": ["member"],
    "where": {"member": {"email": "[email protected]"}}
}

However instead of filtering it just returns all results.

Can anyone tell me how this can be done?

1

1 Answers

2
votes

You should be able to get the result by querying the model you defined by querying like this.

Model.find({
  include: {
    relation: "member",
    scope: {
      fields: [ email, username, etc ], // define which fields to include in the result
      where: { "email": "[email protected]" }, // only select member with specific email
    }
  }
});

In your previous attempt, your where clause was not applied to the member but to the `model``

Check out the documentation on include filters https://loopback.io/doc/en/lb3/Include-filter.html