Query parent based on hasAndBelongsToMany children

1 view
Skip to first unread message

Paul Cowan

unread,
Jan 14, 2017, 2:12:34 AM1/14/17
to LoopbackJS
I have a feedback model:

{
  "name": "Feedback",
  "plural": "Feedback",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "text": {
      "type": "string",
      "required": true
    },

  },
  "validations": [],
  "relations": {
    "tags": {
      "type": "hasAndBelongsToMany",
      "model": "Tag",
      "foreignKey": ""
    }
  },
  "acls": [],
  "methods": {}
}

That has a hasAndBelongsToMany relationship with tags:

{
  "name": "Tag",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

I want to return only feedback models that have certain tag children, the following query just returns all the Feedback models and it is not filtered.  

Can somebody point out what I am doing wrong?

      const result = yield Feedback.find({
        include: {
          relation: "tags",
          scope: {
            where: {
              name: { inq: ['BETA_FEEDBACK']}
            }
          }
        }
      }) 



Reply all
Reply to author
Forward
0 new messages