Loopback.io 找到包含



我正在使用 Loopback.io,与MongoDB。我不知道如何使用"包含"过滤器。

目标是在完成find()或findOne()时将"theuser"完全包含在"组"中。我现在得到的只是一个数组中的 id。谢谢

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": []
}

我正在尝试找到这样的组:

Group.findOne({
        filter: {
            where: {"ownerId": 1},
            include: {relation: "clients"}
        }
}
Group.findOne({
  where: {
    ownerId: 1
  },
  include: 'clients'
}, cb);

相关内容

最新更新