Select to view content in your preferred language

Modify Relationship Class Keys

215
4
2 weeks ago
Teresa_Blader
Frequent Contributor

I have a feature layer with like 6 relationship classes in it, one of which i need to correct the foreign key. This feature layer has like 4 views and is apart of many apps, maps, surveys etc so overwriting would cause some issues.

It turns out I made a mistake with one of the 1:M feature layer: table relationship classes. I used the wrong field for the foreign key. This related table is actually empty and has been mostly been irrelevant, but I now have some data to load. 

How can I correct this without download as a fgdb and totally overwriting the whole service? I have a lot of popups and form arcade expressions I would be so sad to lose. This is hosted in ArcGIS Online. 

Teresa Blader
Olmsted County GIS
GIS Analyst - GIS Solutions
0 Kudos
4 Replies
KVNSCK
by Esri Contributor
Esri Contributor

Hi @Teresa_Blader 

I hope you're having a good day! Based on what I found, the supported workflow is to update the relationship in ArcGIS Pro and then overwrite the hosted feature layer. However, relationships can also be added or removed through the REST API by modifying the layer's service definition. 

Since your related table is already configured and you only need to change the foreign key field, it may be worth investigating whether the service definition can be updated directly instead. That said, this is not an officially supported workflow. There is room for error, and you could potentially break your data, so I strongly recommend testing it on a copy first.

I've attached an image showing what these relationships look like within the layer's definition. The keyField property contains the foreign key information you would want to update. Once again, because this workflow is unsupported, there is very little documentation available. My assumption is that if a relationship can be added or removed by adding onto the service definition, it may also be possible to modify an existing one in the same way.

The most relevant information I found on this was in an older Esri Community post where a user successfully added a relationship using this approach. One important detail they noted is that the changes had to be made to the definition of each individual layer rather than to the service definition as a whole.

I hope this is some helpful food for thought. Going through ArcGIS Pro is what is recommended; it is safer, albeit inconvenient, but I wanted to let you know this seems potentially possible as well.  🙂

KVNSCK_0-1786134397328.pngKVNSCK_0-1786134397328.png

 

Teresa_Blader
Frequent Contributor

Thanks! @KVNSCK I was too scared to try and update the definition. So at some point I'll make a copy and try that. I was able to add a relationship to the definition using ArcGIS Notebooks. I had to repeat this for the views, as just adding it to the "parent" service and updating the view didn't bring that new relationship class into the view, and so I couldn't add it to the popup in the view until I repeated it on the view. This wasn't modifying the existing relationship class, but at least works... I think ...🤔😬😅

Oddly .tables syntax restarts the index at 0, even if the index in the feature service for the first table is like 2 or something.

This was from this post: Solved: Adding Relationship Class to Featue Service - Esri Community

I also tried to delete the mistake relationship classes, but you cannot delete when there are views. The script from here gave me an error: Deleting Relationship Class from Featue Service - Esri Community

Teresa_Blader_1-1786379599085.pngTeresa_Blader_1-1786379599085.png

Teresa_Blader_0-1786378868075.pngTeresa_Blader_0-1786378868075.png

 

Teresa Blader
Olmsted County GIS
GIS Analyst - GIS Solutions
0 Kudos
Teresa_Blader
Frequent Contributor

@KVNSCK  Did you find Update Definition in the supported operations? I'm wondering if there are views, if Esri does not expose that operation.😢

Teresa_Blader_0-1786382433414.pngTeresa_Blader_0-1786382433414.png

Oops!! Never mind - found it in admin 😅

Teresa Blader
Olmsted County GIS
GIS Analyst - GIS Solutions
KVNSCK
by Esri Contributor
Esri Contributor

Hi @Teresa_Blader ! I'm real happy you were able to find something that worked for you (I don't blame you one bit for not touching the definition 😅)

I just tested on my end, and it looks like you're right; any data referenced by view layers (both a joined view or regular view) prevent that script from working. I reckon trying it manually would likely return the same result as well. Nonetheless, thanks for linking those resources; I'll keep them in my toolbox in case I run into anything similar! 🙂

 

 

0 Kudos