How to access reverse direct relations through sdk
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.
Page 1 / 1
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’`.
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?
There are two cases.
If the direct relation of the other side is a single direct relation, use the query method. client.data_modeling.instances.query(...) You can see an example in the pygen example here.
If the direct relation of the other side is a list of direct relations, use the search method. client.data_modeling.instances.search(...). You will do a lookup on the nodes with the direct relation filtering for matching the nodes with the reverse direct relation.
The pygen example for client.data_modeling.instances.query(...) is not very clear and what I am trying is not working.
when I useclient.data_modeling.instances.search(...)without the query because I want everything and with limit= None, I get only 100 records, whereas I have much more than them. When I increase the limit to 1000 it gives 1000 records, I have more than 1000 as well. Ideally, I expect all the data to come when I pass limit=None.
Give me a few days, and I will create a full example in the SDK docs on how to do this.
Thank you, so when I use the search() for reverse direct relation of listable relation, I see that we get 1000 instances by using client.data_modeling.instances.search(activity_view, filter=is_equipment, limit=1_000)
I am not getting any cursor or any other way to retrieve the full data, all the instances satisfied with the query, can you please help me with this?
@Anders Albert - We still are not able to get the complete data with the temporarily approach or query suggested ? Do you see any code change is required in sdk or some other way of querying is required.
We are blocked as of now due to this.
Appreciate if you can expedite your response here.
I cannot make sense what is written in the link. I assume there is a problem in formatting, could you please give the example in a better format so that I can understand? :)
Seems the documentation was broken. Should be fixed now. Can you try again?
I read the documentation. It seems that we are assuming in the example that one equipment can have maximum 1000 activities only. Two observations on this from our side:
In our use case we can have more than 1000 instances for one equipment.
Filtering approach will not be performant as we process a lot of data in our application.
We want to understand:
Any strong reason for not supporting this in query SDK.
If the above feature is not possible for some reason, for a performant solution we would need support for pagination in search.
This is a limitation on the server side with the /search endpoint. If you want to do an exhaustive, you have the use the /list endpoint, which is implemented in the `.list(...)` method in the SDK.
This is a trade-off. Search is high-performant good for fetching specific items fast. The `.list()` is slower but supports pagination (baked in to the SDK) so you can do an exhaustive listing.