1

migrating from lb2 to lb4, skipping lb3 ...

A bunch of caveats. Have this filter with many relations inside:

{
    "limit": 10,
    "skip": 0,
    "where": {},
    "include": [{
        "relation": "userRoles",
        "scope": {
            "include": [{
                "relation": "role"
            }]
        }
    }, {
        "relation": "userCounteragents"
    }, {
        "relation": "userByUserCategories",
        "scope": {
            "include": [{
                "relation": "userCategory"
            }]
        }
    }]
}

Is it possible to filter by "relation": "role" where column role.name == "admin" on whole global search ? Not just filtered inside "relation": "role"

Something like {"limit": 10, "skip": 0, "where": {"userRoles.role.name": "admin"} ...

1 Answers1

1

Unfortunately, LB4 doesn't support inner join (https://github.com/strongloop/loopback-next/issues/4299).

For NoSQL, the only workaround I can think of for your case is to switch the relation to "embedsMany". Otherwise you can create an even simpler design with roles: string[] property.

  • embedsMany is not documented ? simpler design with roles: string[] - you mean reversed query from `/role?filter={"where": {"name":"admin"} ...` including backward relations ? – Dmitry Vasechkin Jul 22 '20 at 05:54
  • When saying simpler roles design I mean to replace the role model/relation with a simple string array property, example: https://github.com/strongloop/loopback4-example-shopping. This of course can be done only if you don't need any additional properties inside the role. – Nikos Oikonomou Jul 22 '20 at 06:06
  • Lb4 doc doesn't offer a page for embedsMany but it's mentioned at the root relations doc: https://loopback.io/doc/en/lb4/Relations.html. It's compatible with the hasMany so you can use its page as a reference. – Nikos Oikonomou Jul 22 '20 at 06:11