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 are used to store attributes of the relationship itself 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.

Syntax

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)
ParameterExplanationData 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

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

  • SIMPLEAn association where each object is independent of each other (a parent-to-parent relationship). This is the default.
  • COMPOSITEAn association where the lifetime of one object controls 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/feature class to the destination table/feature class.

String
backward_label

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

String
message_direction

The direction messages 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 propagated. This is the default.
  • FORWARDMessages propagated from the origin to the destination.
  • BACKWARDMessages propagated from the destination to the origin.
  • BOTHMessages propagated from the origin to the destination and from the destination to the origin.
String
cardinality

The cardinality of the relationship between the origin and destination.

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

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

Table View
attribute_fields
[attribute_fields,...]

The fields containing attribute values that will be added to the relationship class.

Field
origin_primary_key

The field in the origin table that will be used to create the relationship. Generally, this is the object identifier field.

String
origin_foreign_key

The name of the Foreign Key field in the relationship table that refers to the Primary Key field in the origin table/feature class.

String
destination_primary_key

The field in the destination table that will be used to create the relationship. Generally, this is the object identifier field.

String
destination_foreign_key

The field in the relationship table that refers to the Primary Key field in the destination table.

String

Code sample

TableToRelationshipClass Example (Python Window)

The following Python Window script demonstrates how to use the TableToRelationshipClass tool.

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 parcel feature class and 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)

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics