Skip to main content

Hello team, 

I am trying to get the details of a reverse direct relation from my data model. In the SDK documentation I found some sdk methods. I have tried client.data_modeling.views.ReverseDirectRelation(source= "Entity", through="entityType") but I am getting the error that ReverseDirectRelation is not found in views could you please tell me what SDK method I should use to retrieve information on ReverseDirectRelations from my models.

Hi @Gargi Bhosale ,

You cannot get the reverse direct relations using the .retrieve or .list methods, you have to use the .query method. Typically, you do have to use the `NodeResultExpression` with `node.through` set to the direct relation property of the view on the other side of the reverse direct relations and the `nodes.direction=’inwards’`. 

An alternative is to use `pygen`. `pygen` generates a tailor made SDK for your data model. In the generated, `.list` method there is a parameter `retrieve_connections` that you can use to retrieve connections. This will do the `.list` or `.query` call for you. See https://cognite-pygen.readthedocs-hosted.com/en/latest/usage/listing_filtering_retrieving.html#reading-instances-list-and-retrieve


I see that pygen is highly specific on a particular model. In my case ,I intend to make the code generic to any model the user would select. In that case, would you recommend using the .query method? Are there any performance differences between the both?


Reply