Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loopback Filter Based On Related Model Properties

Tags:

loopbackjs

I want to be able to filter based on the properties of related models. For example, I have a Class object with a Building object. I want to get a list of classes that take place in a certain building.

This filter

{  
   "include":"building",
   "scope":{  
      "where":{  
         "name":"warehouse"
      }
   }
}

returns all classes, but only includes building if its name is "warehouse". What I want is for the where clause on building name to apply to the whole filter so that I only get the class if it's building has that name.

Is there any way to do what I want?

Thanks!

like image 645
ishmandoo Avatar asked Mar 28 '15 19:03

ishmandoo


2 Answers

You can do this in code, see include with filters in the docs.

I'm not sure about the JSON but I think it should look more like this:

  "include": {
    "relation": "building",
    "scope": {
      "where": {"name": "warehouse"}
    }
  }
like image 184
Bryan Clark Avatar answered Jan 02 '23 12:01

Bryan Clark


At the moment this is not possible. The issue has been described in this topic; https://github.com/strongloop/loopback/issues/517

It looks like Strongloop is not going to implement this feature in the near future.

like image 26
Erik Verheij Avatar answered Jan 02 '23 13:01

Erik Verheij