While creating new relation in a NodeJS LoopBack project, I encountered this problem:

TypeError: ids.filter is not a function

I could not find a solution on Google, so it took some experimenting to make it work:

In the relations part of my model (a User), the code looked something like this:

"relations": {
    "group": {
      "type": "belongsTo",
      "model": "Group",
      "foreignKey": "group"
    }

Here, I wanted to create a relation, which should tell the User model that it "belongsTo" a Group.
The problem with this ( and I am positive it is documented somewhere in the LoopBack API) that the "foreignKey" is not an ID.
As you know, the foreignKey attribute is automatically created in the other model of the relation (Group) and given the name you define here.

BUT: LoopBack does not recognize an attribute as a foreign key to another model if the attribute name does not end with "Id".

The Solution

Solution 1: Add "Id" to the foreign key attribute name

    "relations": {
        "group": {
          "type": "belongsTo",
          "model": "Group",
          "foreignKey": "groupId"
         }

Solution 2: Leave the foreignKey Attribute empty in your relation declaration: Loopback will generate the attribute in the other model by using the camel case of the declaring model name and appended with "Id". So here the it becomes "groupId" without specifying anything automatically.

    "relations": {
        "group": {
          "type": "belongsTo",
          "model": "Group"
         }