Table To Relationship Class (Data Management)

Summary

Creates an attributed relationship class from the origin, destination, and relationship tables.

Usage

  • This tool creates a table in the database containing the selected attribute fields of the relationship table. These fields store attributes of the relationship that are not attributed to either the origin or destination class. For example, in a parcel database, you may have a relationship class between parcels and owners in which owners own parcels and parcels are owned by owners. An attribute of that relationship may be percentage ownership.

  • Simple or peer-to-peer relationships are relationships between two or more objects in the database that exist independently of each other. For example, in a railroad network, you may have railroad crossings that have one or more related signal lamps. However, a railroad crossing can exist without a signal lamp, and signal lamps 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 a relationship 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 to the origin class. In the pole-transformer example, a backward path label might be: Transformers are mounted on poles.

Parameters

LabelExplanationData Type
Origin Table

The table or feature class that will be associated to the destination table.

Table View
Destination Table

The table or feature class that will be associated to the origin table.

Table View
Output Relationship Class

The relationship class that will be created.

Relationship Class
Relationship Type

Specifies the type of association that will be created between the origin and destination tables.

  • SimpleEach object will be independent of each other (a parent-to-parent relationship). This is the default.
  • CompositeThe lifetime of one object will control the lifetime of its related object (a parent-child relationship).
String
Forward Path Label

A label describing the relationship as it is traversed from the origin table or feature class to the destination table or feature class.

String
Backward Path Label

A label describing the relationship as it is traversed from the destination table or feature class to the origin table or feature class.

String
Message Direction

Specifies the direction messages that will be propagated between the objects in the relationship. 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.

  • None (no messages propagated)No messages will be propagated. This is the default.
  • Forward (origin to destination)Messages will be propagated from the origin to the destination.
  • Backward (destination to origin)Messages will be propagated from the destination to the origin.
  • Both directionsMessages will be propagated from the origin to the destination and from the destination to the origin.
String
Cardinality

Specifies the cardinality of the relationship between the origin and destination.

  • One to one (1:1)Each object of the origin table or feature class can be related to zero or one object of the destination table or feature class. This is the default.
  • One to many (1:M)Each object of the origin table or feature class can be related to multiple objects in the destination table or feature class.
  • Many to many (M:N)Multiple objects of the origin table or feature class can be related to multiple objects in the destination table or feature class.
String
Relationship Table

The table containing attributes that will be added to the relationship class.

Table View
Attribute Fields

The names of the fields containing attribute values that will be added to the relationship class. The fields must be present in the Relationship Table parameter value.

Field
Origin Primary Key

The field in the origin table that will be used to create the relationship.

String
Origin Foreign Key

The name of the field in the relationship table that refers to the primary key field in the origin table or feature class. For table-based relationship classes, these values are used to populate the relationships in the relationship class so they cannot be null.

String
Destination primary key

The field in the destination table that will be used to create the relationship.

String
Destination Foreign Key

The field in the relationship table that refers to the primary key field in the destination table or feature class. For table-based relationship classes, these values are used to populate the relationships in the relationship class so they cannot be null.

String

arcpy.management.TableToRelationshipClass(origin_table, destination_table, out_relationship_class, relationship_type, forward_label, backward_label, message_direction, cardinality, relationship_table, attribute_fields, origin_primary_key, origin_foreign_key, destination_primary_key, destination_foreign_key)
NameExplanationData Type
origin_table

The table or feature class that will be associated to the destination table.

Table View
destination_table

The table or feature class that will be associated to the origin table.

Table View
out_relationship_class

The relationship class that will be created.

Relationship Class
relationship_type

Specifies the type of association that will be created between the origin and destination tables.

  • SIMPLEEach object will be independent of each other (a parent-to-parent relationship). This is the default.
  • COMPOSITEThe lifetime of one object will control the lifetime of its related object (a parent-child relationship).
String
forward_label

A label describing the relationship as it is traversed from the origin table or feature class to the destination table or feature class.

String
backward_label

A label describing the relationship as it is traversed from the destination table or feature class to the origin table or feature class.

String
message_direction

Specifies the direction messages that will be propagated between the objects in the relationship. 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.

  • NONENo messages will be propagated. This is the default.
  • FORWARDMessages will be propagated from the origin to the destination.
  • BACKWARDMessages will be propagated from the destination to the origin.
  • BOTHMessages will be propagated from the origin to the destination and from the destination to the origin.
String
cardinality

Specifies the cardinality of the relationship between the origin and destination.

  • ONE_TO_ONEEach object of the origin table or feature class can be related to zero or one object of the destination table or feature class. This is the default.
  • ONE_TO_MANYEach object of the origin table or feature class can be related to multiple objects in the destination table or feature class.
  • MANY_TO_MANYMultiple objects of the origin table or feature class can be related to multiple objects in the destination table or feature class.
String
relationship_table

The table containing attributes that will be added to the relationship class.

Table View
attribute_fields
[attribute_fields,...]

The names of the fields containing attribute values that will be added to the relationship class. The fields must be present in the relationship_table parameter value.

Field
origin_primary_key

The field in the origin table that will be used to create the relationship.

String
origin_foreign_key

The name of the field in the relationship table that refers to the primary key field in the origin table or feature class. For table-based relationship classes, these values are used to populate the relationships in the relationship class so they cannot be null.

String
destination_primary_key

The field in the destination table that will be used to create the relationship.

String
destination_foreign_key

The field in the relationship table that refers to the primary key field in the destination table or feature class. For table-based relationship classes, these values are used to populate the relationships in the relationship class so they cannot be null.

String

Code sample

TableToRelationshipClass example (Python window)

The following Python window script demonstrates how to use the TableToRelationshipClass function.

import arcpy
arcpy.env.workspace = "C:/data/Montgomery.gdb"
arcpy.TableToRelationshipClass_management("owners", "Parcels", "ownersParcels_RelClass",
                                          "SIMPLE", "Owns", "Is Owned By", "BACKWARD",
                                          "MANY_TO_MANY", "owners", ["OWNER_PERCENT", "DEED_DATE"],
                                          "OBJECTID", "owner_id", "OBJECTID", "parcel_id")
TableToRelationshipClass example (stand-alone script)

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

# Name: TableToRelationshipClass.py
# Description: Create an attributed 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 attributed 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"
attributeFields = ["OWNER_PERCENT", "DEED_DATE"]
originPK = "OBJECTID"
originFK = "owner_ID"
destinationPK = "OBJECTID"
destinationFK = "parcel_ID"
arcpy.TableToRelationshipClass_management(ownerTbl, parcel, relClass, "SIMPLE",
                                          forLabel, backLabel, "BACKWARD", "MANY_TO_MANY",
                                          ownerTbl, attributeFields, originPK, originFK,
                                          destinationPK, destinationFK)

Related topics