I have created a script tool that allows the user to choose a spatial extent and export several feature classes within that extent and (what is supposed to be) a related table to a new file geodatabase. Within the master database where the exports are coming from, there is a relationship class between one of the feature classes and the table. I am unsure of the best way to maintain the relationship (or create a new one) so that the records in the exported table reflect the related records that were deleted during the spatial extent clipping.
I have attempted to export the feature classes and table and then create a new relationship class within the geodatabase. When I do this, the relationship works for any records deleted manually afterwards. However, there are still a bunch of records in the table (destination table) that do not exist in the feature class (origin table) because they were not updated when the relationship class was created. I have also tried creating the relationship class in the GDB prior to copying the features and table into it - this gives the same result.
Is there a specific way to make sure a relationship class works retroactively? Or is there a better way to do this?
Here is my code for this part of the script:
output = arcpy.CreateFileGDB_management(workspace, gdb_name) gdb = output.getOutput(0) # make NHA_Core feature layer from selection and copy to new GDB core_lyr = arcpy.MakeFeatureLayer_management(NHA_Core, "core_lyr") core_selection = arcpy.SelectLayerByAttribute_management(core_lyr, "NEW_SELECTION", '"STATUS" = \'C\' or "STATUS" = \'NP\'') if len(clip_lyr) > 0: core_selection = arcpy.SelectLayerByLocation_management(core_lyr, "INTERSECT", clip_lyr, "", "SUBSET_SELECTION", "") else: core_selection = arcpy.SelectLayerByLocation_management(core_lyr, "INTERSECT", interactive_selection, "", "SUBSET_SELECTION", "") Core = arcpy.CopyFeatures_management(core_selection, os.path.join(gdb, "NHA_Core")) arcpy.DeleteField_management(Core, deleteFields) Species = arcpy.CopyRows_management(NHA_SpeciesTable, os.path.join(gdb, "NHA_SpeciesTable")) arcpy.CreateRelationshipClass_management(Core, Species, os.path.join(gdb, "NHA_Core_Species"), "COMPOSITE", "NHA_SpeciesTable", "NHA_Core", "FORWARD", "ONE_TO_MANY", "NONE", "NHA_JOIN_ID", "NHA_JOIN_ID")