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?
The pygen example for client.data_modeling.instances.query(...) is not very clear and what I am trying is not working.
this is what I am trying can you please correct?
from cognite.client.data_classes.data_modeling.query import Query, Select, NodeResultSetExpression, EdgeResultSetExpression, SourceSelector
view=ViewId(space='slb-pdm-dm-governed', external_id='Property', version='1_7')
nested_prop_view_id = ViewId(space='slb-pdm-dm-governed', external_id='PropertyType', version='1_6')
properties = ="externalId", "propertyType"]
nested_prop_view_properties=s"externalId"]
query= Query(
with_={"PropertyType":NodeResultSetExpression(
from_="Property",
direction="inwards",
filter= HasData(views=snested_prop_view_id]),
through=nested_prop_view_id.as_property_ref("directSingle"),
)},
select={"PropertyType": Select(tSourceSelector(nested_prop_view_id, nested_prop_view_properties)])}
)
res1 = client.data_modeling.instances.query(query)
Another important observation:
when I use client.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.