Create Relationship Class (Data Management)

Summary

This tool creates a relationship class to store an association between fields or features in the origin table and the destination table.

Usage

Syntax

CreateRelationshipClass_management (origin_table, destination_table, out_relationship_class, relationship_type, forward_label, backward_label, message_direction, cardinality, attributed, origin_primary_key, origin_foreign_key, {destination_primary_key}, {destination_foreign_key})
ParameterExplanationData Type
origin_table

The table or feature class that is associated to the destination table.

Table View
destination_table

The table that is associated to the origin table.

Table View
out_relationship_class

The relationship class that is created.

Relationship Class
relationship_type

The type of relationship to create between the origin and destination tables.

  • SIMPLEA relationship between independent objects (parent to parent). This is the default.
  • COMPOSITEA relationship between dependent objects where the lifetime of one object controls the lifetime of the related object (parent to child).
String
forward_label

A name to uniquely identify the relationship when navigating from the origin table to the destination table.

String
backward_label

A name to uniquely identify the relationship when navigating from the destination table to the origin table.

String
message_direction

The direction in which messages are passed between the origin and destination tables. For example, in a relationship between poles and transformers, when the pole is deleted, it sends a message to its related transformer objects informing them it was deleted.

  • FORWARDMessages are passed from the origin to the destination table.
  • BACKMessages are passed from the destination to the origin table.
  • BOTHMessages are passed from the origin to the destination table and from the destination to the origin table.
  • NONENo messages passed. This is the default.
String
cardinality

Determines how many relationships exist between rows or features in the origin and rows or features in the destination table.

  • ONE_TO_ONEEach row or feature in the origin table can be related to zero or one row or feature in the destination table. This is the default.
  • ONE_TO_MANYEach row or feature in the origin table can be related to one or several rows or features in the destination table.
  • MANY_TO_MANYSeveral fields or features in the origin table can be related to one or several rows or features in the destination table.
String
attributed

Specifies if the relationship will have attributes.

  • NONEIndicates the relationship class will not have attributes. This is the default.
  • ATTRIBUTEDIndicates the relationship class will have attributes.
Boolean
origin_primary_key

The field in the origin table, typically the OID field, that links it to the Origin Foreign Key field in the relationship class table.

String
origin_foreign_key

The field in the relationship class table that links it to the Origin Primary Key field in the origin table.

String
destination_primary_key
(Optional)

The field in the destination table, typically the OID field, that links it to the Destination Foreign Key field in the relationship class table.

String
destination_foreign_key
(Optional)

The field in the relationship class table that links it to the Destination Primary Key field in the destination table.

String

Code Sample

Create Relationship Class example (Python window)

The following Python Window script demonstrates how to use the Create Relationship Class tool.

import arcpy
arcpy.env.workspace = "C:/data/Habitat_Analysis.gdb"
arcpy.CreateRelationshipClass_management("vegtype", "vegtable", "veg_RelClass", "SIMPLE", "Attributes from vegtable", "Attributes and Features from vegtype", "NONE", "ONE_TO_ONE", "NONE", "HOLLAND95", "HOLLAND95")
Create Relationship Class example 1 (Stand-alone script)

Create a relationship class between vegetation feature class and table with additional vegetation information.

# Name: CreateRelationshipClass.py
# Description: Create a relationship class between vegetation feature
#                    class and table with additional vegetation information
# Author: ESRI

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Copy vegtable.dbf to file gdb table, since both tables to be related
#  must be in the same database
vegDbf = "vegtable.dbf"
vegTbl = "Habitat_Analysis.gdb/vegtable"
arcpy.CopyRows_management(vegDbf, vegTbl)

# Create simple relationship class between 'vegtype' vegetation layer
#  and 'vegtable' table with additional vegetation information
veg = "Habitat_Analysis.gdb/vegtype"
relClass = "Habitat_Analysis.gdb/veg_RelClass"
forLabel = "Attributes from vegtable"
backLabel = "Attributes and Features from vegtype"
primaryKey = "HOLLAND95"
foreignKey = "HOLLAND95"
arcpy.CreateRelationshipClass_management(veg, vegTbl, relClass, "SIMPLE", forLabel, 
					      backLabel, "NONE", "ONE_TO_ONE", 
					     "NONE", primaryKey, foreignKey)
Create Relationship Class example 2 (Stand-alone script)

Create a relationship class between parcel feature class and a table with owner information.

# Name: CreateRelationshipClass.py
# Description: Create a relationship class between parcels feature
#                    class and table with owner information
# Author: ESRI

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Copy owners.dat to file gdb table, since both tables to be related
#  must be in the same database
ownerDat = "owners.dat"
ownerTbl = "Montgomery.gdb/owners"
arcpy.CopyRows_management(ownerDat, ownerTbl)

# Create simple relationship class between 'parcel' parcel layer
#  and 'owner' table with additional parcel owner information
parcel = "Montgomery.gdb/Parcels"
relClass = "Montgomery.gdb/parcelowners_RelClass"
forLabel = "Owns"
backLabel = "Is Owned By"
primaryKey = "PROPERTY_ID"
foreignKey = "PROPERTY_I"
arcpy.CreateRelationshipClass_management(ownerTbl, parcel, relClass, "SIMPLE", forLabel, 
					     backLabel, "BACKWARD", "ONE_TO_MANY", 
					     "NONE", primaryKey, foreignKey)

Environments

Related Topics

Licensing Information

ArcView: No
ArcEditor: Yes
ArcInfo: Yes

10/27/2014