Select to view content in your preferred language

How to identify parent without child

367
1
06-10-2019 12:48 PM
JoseSanchez
Frequent Contributor

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)