Select to view content in your preferred language

Re-uploading feature classes with attachment tables

268
0
07-22-2022 12:55 PM
Labels (3)
AlfredBaldenweck
MVP Regular Contributor

Hi all, I came across this issue and was wondering if anyone else had it.

On Pro 2.9:

I'm trying to consolidate some feature services. Since that isn't possible (Please vote for relevant ideas here and here), I've resorted to downloading all of them to a local gdb and then republishing them as one service.

This normally works, but I found that if a feature class with an attachment table was included, the process would fail. Testing shows that it doesn't occur when publishing a feature class/attachment table that was created locally; it's specifically those that were previously hosted.

This behaviour occurs regardless of the original feature service, and regardless of the number of them included.

I deleted the relationship classes and everything worked; I was able to upload the feature classes and their attachment tables just fine.

Has anyone else had this problem? If so, I'd like to log a bug report.

I was able to restore the relationships in the feature service. 
A large amount of this method was taken from @ Clubdebambos's great blog post about combining feature services Add Table from Hosted Service to Another and Creat... - Esri Community

Here's my code:

 

 

import arcgis
agol= arcgis.GIS("home")

search= agol.content.search('title: Mamalahoa 2021 (PMIS 217667) Field Data','Feature Layer')
flc= search[0]

for tbl in flc.tables:
  #Get the table's feature class it's supposed to match
  #You should probably preface this with an .endswith("__ATTACH") if you have other tables
	lay = tbl.properties.name.split("__")[0]
	for lyr in flc.layers:
		if lyr.properties.name == lay: #check to see if the attachment table matches something
			print(f"{lyr.properties.name}, {tbl.properties.name}")
			#Set up the relationships
            lyr_rel_dict = {
				"name": "Layer_to_Table",
				"relatedTableId": int(tbl.properties.id),
				"cardinality": "esriRelCardinalityOneToMany",
				"role": "esriRelRoleOrigin",
				"keyField": "GlobalID",
				"composite": True
			}
				
			tbl_rel_dict = {
				"name": "Table_to_Layer",
				"relatedTableId": int(lyr.properties.id),
				"cardinality": "esriRelCardinalityOneToMany",
				"role": "esriRelRoleDestination",
				"keyField": "REL_GLOBALID",
				"composite": True
			}
			# Add the relationships to both tables
			lyr.manager.add_to_definition({"relationships" : [lyr_rel_dict]})
			tbl.manager.add_to_definition({"relationships" : [tbl_rel_dict]})
			
			print(lyr.properties.relationships)
			
#double check
#get the information fresh, otherwise it won't appear
#and you'll run it again and have two relationships 
#per table/feature class pair
search= agol.content.search('title: Mamalahoa 2021 (PMIS 217667) Field Data','Feature Layer')
flc= search[0]
for lyr in flc.layers:
    print(f"{lyr.properties.name}, {lyr.properties.relationships}")
for tbl in flc.tables:
    print(f"{tbl.properties.name}, {tbl.properties.relationships}")

 

 

0 Kudos
0 Replies