Select to view content in your preferred language

relate a hosted table and feature layer arcgis

647
2
05-28-2024 12:11 PM
Labels (1)
StephenAsamoah
New Contributor

I currently using the ArcGIS API for python to relate create a hosted table and feature layer. I am trying to relate the two with 2 one to many relationships using the API. I am making use of the manager.update_definition function, passing in "relationships" attributes similar to this:

response = layer.manager.update_definition({"relationships": [relationship]})
 
layer is a feature layer taken from: layer = FeatureLayer(url, gis = gis)
relationship is an object of the form relationship = {
            "id": layer.properties.serviceItemId,
            "name": "Layer_to_Table",
            "relatedTableId": layer.properties.serviceItemId,
            "cardinality": "OneToOne",
            "role": "esriRelRoleOrigin",
            "keyField": table.properties.serviceItemId,
            "relatedKeyField": "table_id",
            "composite": True
        }
 
This always seems to fail throwing a 500 error code that says "Field 'relationships" cannot be updated. I know the response object is supposed to give an indication as to if the operation was successful or not (and the reason) but it doesn't even get to that point to potentially see what the issue is. Any ideas what the potential issue could be, and if I'm even using the correct approach. 
If not, what would the correct approach be.
 
Thanks
0 Kudos
2 Replies
StephenAsamoah
New Contributor
0 Kudos
Clubdebambos
MVP Regular Contributor

**UPDATE: There seems to be a bug with using the ArcGIS API for Python to add a relationship when using Portal (works fine in ArcGIS Online) for Hosted Feature Services. See here.

 

Hi @StephenAsamoah,

I wrote that guide. It seems the construction of your relationship dictionary is causing the problem, see notes below.

relationship = {
    "id": 0, # this is an integer, the id will also be the same in the related relationship dictionary
    "name": "Layer_to_Table",
    "relatedTableId": 0, # this is an integer representing the id in the layer/table url
    "cardinality": "OneToOne", # esriRelCardinalityOneToOne or esriRelCardinalityOneToMany
    "role": "esriRelRoleOrigin",
    "keyField": table.properties.serviceItemId, # a field name from the origin layer/table
    "relatedKeyField": "table_id", # not required
    "composite": True
}

 All the best,

Glen

~ learn.finaldraftmapping.com
0 Kudos