Table To Relationship Class (Data Management)

Summary

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

Usage

Syntax

TableToRelationshipClass_management (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)

Environments

Related Topics

Licensing Information

ArcView: No
ArcEditor: Yes
ArcInfo: Yes

10/27/2014