How to identify parent without child

69
1
06-10-2019 12:48 PM
JoseSanchez
Occasional Contributor III

Hello everyone,

In a  RelationshipClass  between a FC (Parent) and a Table (child)  How can I identify the aren't that do not have a child, or features in the Fc that do not have records associated in the table.

Thanks

0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor

Hi Jose,

You could do this using Python.  Ex:

import arcpy
from arcpy import env

env.workspace = r"C:\temp\python\test.gdb"
parentLayer = 'Airports'
childLayer = 'Districts'

# Get list of foreign keys
foreignKey = [row[0] for row in arcpy.da.SearchCursor(childLayer, ["FCC"])]

# Convert list to tuple
primaryKey = ()
for id in foreignKey:
primaryKey += (str(id) ,)

# Search for primary keys that are not in foreignKey tuple and print OBJECTID
query = "NOT FCC IN {0}".format(primaryKey)
noChildIds = [row[0] for row in arcpy.da.SearchCursor(parentLayer, ["OBJECTID"], query)]
print(noChildIds)