Skip to main content
Question

Proper query for accessing reverse direct relation

  • January 3, 2025
  • 4 replies
  • 122 views

Forum|alt.badge.img

Hello team,

 

We have tried to query Entity view which has a property properties of type view Property which is a reverse direct relation.

We are using the query endpoint and the instances.query() sdk method to do so.

We want the details of properties to come in the select object of Entity. Providing the query below:

{

"with": {

"0": {

"limit": 50,

"nodes": {

"filter": {

"and": [

{

"matchAll": {}

},

{

"hasData": [

{

"type": "view",

"space": "slb-pdm-dm-governed",

"externalId": "Entity",

"version": "1_7"

}

]

},

{

"or": [

{

"equals": {

"property": [

"node",

"externalId"

],

"value": "fba80a5d3b994db698e74b77fb96f1de"

}

}

]

}

]

}

}

},

"0_6": {

"limit": 10000,

"nodes": {

"from": "0",

"through": {

"source": {

"type": "view",

"space": "slb-pdm-dm-governed",

"externalId": "Property",

"version": "1_7"

},

"identifier": "entity"

},

"direction": "inwards",

"filter": {

"and": [

{

"matchAll": {}

},

{

"hasData": [

{

"type": "view",

"space": "slb-pdm-dm-governed",

"externalId": "Property",

"version": "1_7"

}

]

}

]

}

}

}

},

"select": {

"0": {

"sources": [

{

"source": {

"type": "view",

"space": "slb-pdm-dm-governed",

"externalId": "Entity",

"version": "1_7"

},

"properties": [

"properties"


]

}

]

},

"0_6": {

"sources": [

{

"source": {

"type": "view",

"space": "slb-pdm-dm-governed",

"externalId": "Property",

"version": "1_7"

},

"properties": [

"name"

]

}

]

}

},

"includeTyping": true

}

But we are not getting any properties details in the entity response.

Basically, we are expecting all the data of properties to come in the Entity response.

Please tell us the correct Select syntax to achieve this.

 

4 replies

Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8

@Gargi Bhosale can you check whether the discussion below helps for your usecase?

 


Forum|alt.badge.img
  • Author
  • Committed
  • January 4, 2025

@Mithila Jayalath ,

this discussion is around using instances.list() sdk. I want to know about how to acheive my usecase through instances.query()


Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8
  • Seasoned Practitioner
  • February 17, 2025

@Arild Eide will you be able to help out here?


Anders  Albert
Seasoned Practitioner
Forum|alt.badge.img
  • Seasoned Practitioner
  • March 3, 2025

@Gargi Bhosale Your filters looks strange, take the first entry 0:

  '0':
limit: 50
nodes:
filter:
and:
- matchAll: {}
- hasData:
- type: view
space: slb-pdm-dm-governed
externalId: Entity
version: '1_7'
- or:
- equals:
property:
- node
- externalId
value: fba80a5d3b994db698e74b77fb96f1de

This reads as match all and has data and (or node.externalId == fba...). I think the first entry match_all will return zero nodes and thus nothing else will return. Furthermore, it is strange that you both filter for a view and a very specific node externalId. I would expect something like this is enough.

  '0':
limit: 50
nodes:
filter:
equals:
property:
- node
- externalId
value: fba80a5d3b994db698e74b77fb96f1de

In the 0_6 entry I similarly see a match_all that will return nothing. I would expect something like this is sufficient.

      filter:
hasData:
- type: view
space: slb-pdm-dm-governed
externalId: Property
version: '1_7'

 

Finally, there is something strange about your through section. I am not understanding what you are trying to achieve. Do you want all properties for a given entity? If that is the case, you can simply do it through the list method in the PySDK:

from cognite.client import CogniteClient
from cognite.client import data_modeling as dm

client = CogniteClient()

client.data_modeling.instances.list(filter=dm.filters.Equals(("slb-pdm-dm-governed", "Property/1_7", "entity"), {"space": "<space_of_entity>", "externalId": "fba80a5d3b994db698e74b77fb96f1de"}))