1

I'm using Loopback.io, with MongoDB. I can't figure how to use the "include" filter.

The goal is to have "theuser" be included fully in the "group" when done a find() or findOne(). All I get now is the id's in an array. Thanks

theuser.json:

{
  "name": "theuser",
  "plural": "theusers",
  "base": "User",
  "idInjection": true,
  "properties": {
    "peerId": {
      "type": "string",
      "required": false
    },
    "peerStatus": {
      "type": "string",
      "required": false
    }
  },
  "validations": [],
  "relations": {
    "notes": {
      "type": "hasMany",
      "model": "note",
      "foreignKey": "ownerId"
    },
    "groups": {
      "type": "hasMany",
      "model": "group",
      "foreignKey": "groupId"
    }
  },

group.json:

{
  "name": "group",
  "plural": "groups",
  "base": "PersistedModel",
  "idInjection": true,
  "properties": {
    "name": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {
    "host": {
      "type": "belongsTo",
      "model": "theuser",
      "foreignKey": "ownerId"
    },
    "clients": {
      "type": "hasMany",
      "model": "theuser",
      "foreignKey": "clientId"
    }
  },
  "acls": [],
  "methods": []
}

I'm trying to find a group like so:

Group.findOne({
        filter: {
            where: {"ownerId": 1},
            include: {relation: "clients"}
        }
}
rhymn
  • 121
  • 2
  • 6

1 Answers1

2
Group.findOne({
  where: {
    ownerId: 1
  },
  include: 'clients'
}, cb);
superkhau
  • 2,781
  • 18
  • 9
  • Just a quick comment: "filter" is the entire thing you pass into `findeOne()`, so no need to use that in the object. – Jordan Kasper Apr 23 '15 at 16:42
  • I see, although I can't get this to work. Is it maybe the foreign key setup that is faulty? Thank you – rhymn Jun 12 '15 at 12:40