Label | Explanation | Data Type |
Origin Table | The table or feature class that is associated with the destination table. | Table View |
Destination Table | The table that is associated with the origin table. | Table View |
Output Relationship Class | The relationship class that will be created. | Relationship Class |
Relationship Type | Specifies the type of relationship that will be created between the origin and destination tables.
| String |
Forward Path Label | A name to uniquely identify the relationship when navigating from the origin table to the destination table. | String |
Backward Path label | A name to uniquely identify the relationship when navigating from the destination table to the origin table. | String |
Message Direction | Specifies the direction in which messages will be passed between the origin and destination tables. For example, in a relationship between poles and transformers, when a pole is deleted, a message will be sent to its related transformer objects indicating that it was deleted.
| String |
Cardinality | Specifies how many relationships will exist between rows or features in the origin table and rows or features in the destination table.
| String |
Relationship class is attributed | Specifies whether the relationship class will have attributes.
| Boolean |
Origin Primary Key | For many-to-many or attributed relationship classes, this is the field in the origin table that links to the Origin Foreign Key field in the relationship class table. For one-to-one or one-to-many relationship classes that are not attributed, this is the field in the origin table that links to the Origin Foreign Key field in the destination table. | String |
Origin Foreign Key | For many-to-many or attributed relationship classes, this is the field in the relationship class table that links to the Origin Primary Key field in the origin table. For one-to-one or one-to-many relationship classes that are not attributed, this is the field in the destination table that links to the Origin Primary Key field in the origin table. | String |
Destination Primary Key (Optional) | The field in the destination table that links to the Destination Foreign Key field in the relationship class table. This value is required for many-to-many or attributed relationship classes, but should be left empty for one-to-one or one-to-many relationship classes that are not attributed. | String |
Destination Foreign Key (Optional) | The field in the relationship class table that links to the Destination Primary Key field in the destination table. This value is required for many-to-many or attributed relationship classes, but should be left empty for one-to-one or one-to-many relationship classes that are not attributed. | String |
Summary
Creates a relationship class to store an association between fields or features in the origin table and the destination table.
Usage
Relationships can exist between spatial objects (features in feature classes), nonspatial objects (rows in a table), or spatial and nonspatial objects.
Once created, a relationship class cannot be modified; you can only add, delete, or refine its rules.
For many-to-many relationship classes, a new table is created in the database to store the foreign keys used to link the origin and destination classes. This table can also have other fields to store attributes of the relationship that are not attributed to either the origin class or the destination class. For example, in a parcel database, you might have a relationship class between parcels and owners in which owners own parcels and parcels are owned by owners. An attribute of that relationship might be percentage ownership. One-to-one and one-to-many relationship classes can also have attributes. In this case, a table is created to store the relationships.
Simple or peer-to-peer relationships involve two or more objects in the database that exist independently of each other. For example, in a railroad network, you might have railroad crossings that have one or more related signal lamps. However, a railroad crossing can exist without a signal lamp, and signal lamps can exist on the railroad network where there are no railroad crossings. Simple relationships can have one-to-one, one-to-many, or many-to-many cardinality.
A composite relationship is one in which the lifetime of one object controls the lifetime of its related objects. For example, power poles support transformers, and transformers are mounted on poles. Once a pole is deleted, a delete message is propagated to its related transformers, which are deleted from the transformers' feature class. Composite relationships are always one to many.
Forward and backward path labels describe the relationship when navigating from one object to another. The forward path label describes the relationship navigated from the origin class to the destination class. In the pole-transformer example, a forward path label might be Poles support transformers. The backward path label describes the relationship navigated from the destination class to the origin class. In the pole-transformer example, a backward path label might be Transformers are mounted on poles.
Parameters
arcpy.management.CreateRelationshipClass(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})
Name | Explanation | Data Type |
origin_table | The table or feature class that is associated with the destination table. | Table View |
destination_table | The table that is associated with the origin table. | Table View |
out_relationship_class | The relationship class that will be created. | Relationship Class |
relationship_type | Specifies the type of relationship that will be created between the origin and destination tables.
| 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 | Specifies the direction in which messages will be passed between the origin and destination tables. For example, in a relationship between poles and transformers, when a pole is deleted, a message will be sent to its related transformer objects indicating that it was deleted.
| String |
cardinality | Specifies how many relationships will exist between rows or features in the origin table and rows or features in the destination table.
| String |
attributed | Specifies whether the relationship class will have attributes.
| Boolean |
origin_primary_key | For many-to-many or attributed relationship classes, this is the field in the origin table that links to the origin_foreign_key field in the relationship class table. For one-to-one or one-to-many relationship classes that are not attributed, this is the field in the origin table that links to the origin_foreign_key field in the destination table. | String |
origin_foreign_key | For many-to-many or attributed relationship classes, this is the field in the relationship class table that links to the origin_primary_key field in the origin table. For one-to-one or one-to-many relationship classes that are not attributed, this is the field in the destination table that links to the origin_primary_key field in the origin table. | String |
destination_primary_key (Optional) | The field in the destination table that links to the destination_foreign_key field in the relationship class table. This value is required for many-to-many or attributed relationship classes, but should be left empty for one-to-one or one-to-many relationship classes that are not attributed. | String |
destination_foreign_key (Optional) | The field in the relationship class table that links to the destination_primary_key field in the destination table. This value is required for many-to-many or attributed relationship classes, but should be left empty for one-to-one or one-to-many relationship classes that are not attributed. | String |
Code sample
The following Python window script demonstrates how to use the CreateRelationshipClass function.
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 a relationship class between a vegetation feature class and a 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 a relationship class between a 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_ID"
arcpy.CreateRelationshipClass_management(ownerTbl,
parcel,
relClass,
"SIMPLE",
forLabel,
backLabel,
"BACKWARD",
"ONE_TO_MANY",
"NONE",
primaryKey,
foreignKey)