Querying reverse relationship properties

This topic has 5 replies, 4 voices, and was last updated 6 years, 4 months ago by huy.

  • Author
    Posts
  • #10439
     jayp
    Participant

    Hello,
    I’m using OpenIdM 4.0.0 at the moment. I have created 2 custom managed objects, ObjectA and ObjectB.
    ObjectA can be referenced by 0 to many Object Bs and ObjectB is referencing always 1 and only 1 ObjectA. Now I have created a relationship property to the ObjectB and set it to have reserve relationship, which and named it accordingly. I can query ObjectA and ObjectB via the REST. However, I haven’t been able to query all the ObjectBs the ObjectA is referenced by. I am fairly sure this is possible through the REST, I just haven’t used correctly formatted request. How can I do this kind of querying? Thanks for the help!

    #10441
     laurent.bristiel
    Participant

    Hi,

    You can query all the relationships associated with a managed object by querying the reference (*_ref) property of the object. For example, the following query shows all the objects that are referenced by psmith’s entry:

    
    $ curl \
     --header "X-OpenIDM-Username: openidm-admin" \
     --header "X-OpenIDM-Password: openidm-admin" \
     --request GET \
     "http://localhost:8080/openidm/managed/user/psmith?_fields=*_ref"
    {
      "_id": "psmith",
      "_rev": "1",
      "roles": [],
      "authzRoles": [
        {
          "_ref": "repo/internal/role/openidm-authorized",
          "_refProperties": {
            "_id": "8e7b2c97-dfa8-4eec-a95b-b40b710d443d",
            "_rev": "1"
          }
        }
      ],
      "manager": {
        "_ref": "managed/user/bjensen",
        "_refProperties": {
          "_id": "3a246327-a972-4576-b6a6-7126df780029",
          "_rev": "1"
        }
      }
    }
    

    Is that what you were looking for?

    Laurent

    #10443
     jayp
    Participant

    Thanks for the swift reply. Actually what I am looking for is the opposite of that if you will. In your example you get who is psmith’s manager who is referenced. To use your example what I want to get is all the entries whose manager is bjensen. So basically all the objects that are referencing a specific object.

    #10480
     Jake Feasel
    Moderator

    Something like this should work: /openidm/managed/user/bjensen/reports?_queryFilter=true

    #10485
     jayp
    Participant

    That looks like what I’m looking for. However, cannot get it to work. “Reports” is the reverse property name? I have the ObjectA and ObjectB and ObjectA can be referenced by 0 to many Object Bs and ObjectB is referencing always 1 and only 1 ObjectA. Now I have the property for the relationship in the ObjectB schema and I’ve set the reverse relationship true and named it to objectsAs. So should the query for me be: /openidm/managed/objectA/<uuid>/objectsAs?_queryFilter=true

    I’ve tried that and got 404 not found. Any tips? Thanks for the help, it is highly appreciated.

    #10892
     huy
    Participant

    I did something similar by also adding a property reference object that is an array on ObjectA. This should be what you setup as the reverse property on ObjectB

    A good example of how to set this up would be to look at how managed/user and the Manager and Reports properties are setup as a reference. Essentially you would define the “Manager” property on ObjectB and the “Reports” property on ObjectA, but call them as you see fit. So when you call the REST end point /managed/objectA/_id it should return the reference object “Reports” and list all the ObjectB’s in the relationship.

    Hope that helps

    • This reply was modified 6 years, 4 months ago by huy.
    • This reply was modified 6 years, 4 months ago by huy.
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

©2022 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?