ArcGIS REST API

Relationships (Feature Service)

Description

The relationships resource includes relationship class information for the layers and tables in the service. This allows applications to get all the information in one resource, rather than having to piece together the relationships information in each individual layer and table.

The relationships resource includes information about relationship rules from the back-end relationship classes, in addition to the relationship information already found in the individual layers and tables.

Services that support the relationships resource will have the "supportsRelationshipsResource": true property on their service resource.

For more information on relationship classes in enterprise geodatabases, see Relationship class properties.

Note:
If your relationship class has subtypes, you do not need to define any rules. However, if you define rules for even one of your relationship class subtypes, you must define rules for all of them.

Response Properties

The following properties are returned for each relationship class.

PropertyDetails
id

The unique identifier assigned to each relationship.

Note:

This identifier is not unique per feature service layer, but is unique per feature service.

name

The name assigned to the relationship when the relationship was created.

backwardPathLabel

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

originLayerId

The layer ID of the origin table participating in the relationship.

originPrimaryKey

The name of the primary key field in the origin table.

forwardPathLabel

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

destinationLayerId

The layer ID of the destination table participating in the relationship.

originForeignKey

In a non-attributed relationship, the originForeignKey is the foreign key in the destination relationship class which relates the rows of the destination layer or table to the origin layer or table. In an attributed relationship, originForeignKey is the foreign key in the intermediate table, which relates the rows of the intermediate table to the origin layer or table.

relationshipTableId

The ID of the intermediate table in the feature service for attributed relationships.

Note:

This property will only be exposed if the relationship is attributed.

destinationPrimaryKey

The name of the primary key field in the destination table.

Note:

This property will only be exposed if the relationship is non-attributed.

destinationForeignKey

In attributed relationships, this is the foreign key in the intermediate table that relates the rows of the intermediate table to the destination layer or table.

Note:

This property will only be exposed if the relationship is attributed.

rules

If the relationship class has relationship rules, the rules array will list information about each rule. If no rules are defined, an empty array is returned. The each rule has the following properties:

ruleID - The unique ID of the relationship rule.

originSubtypeCode - The user defined subtype code in the origin table that the relationship rule applies to.

Note:

Check the origin layer for the subTypeField property. If "subTypeField": "", you can ignore the originSubtypeCode property in the relationship rule as the origin layer does not contain subtypes.

originMinimumCardinality - The minimum amount of relationships allowed from the origin table to the destination table. A -1 value for this property means no minimum has been defined.

originMaximumCardinality - The maximum amount of relationships allowed from the origin table to the destination table. A -1 value for this property means no maximum has been defined.

destinationSubtypeCode – The user defined subtype code in the destination table that the relationship rule applies to.

Note:

Check the destination layer for the subTypeField property. If "subTypeField" is empty, you can ignore the destinationSubtypeCode property in the relationship rule, as the destination layer does not contain subtypes.

destinationMinimumCardinality – The minimum amount of relationships allowed from the destination table to the origin table. A -1 value for this property means no minimum has been defined.

destinationMinimumCardinality - The maximum amount of relationships allowed from the destination table to the origin table. A -1 value for this property means no maximum has been defined.

cardinality

The cardinality of the relationships as a combination of origin and destination cardinalities. When you create a relationship class, you create it with an initial cardinality, such as one-to-many or many-to-many.

In a real system, however, relationship cardinalities are more specific. Once you've created the relationship class, you can refine the cardinality by creating rules.

Relationship rules allow you to restrict the type of objects in the origin feature class or table that can be related to a certain kind of object in the destination feature class or table.

Values: esriRelCardinalityOneToOne | esriRelCardinalityOneToMany | esriRelCardinalityManyToMany

If an object in the origin table can be related to only one object in the destination table, the relationship cardinality is esriRelCardinalityOneToOne. If an object in the origin table can be related to multiple objects in the destination table, the relationship cardinality is esriRelCardinalityOneToMany. If an object in the origin table can be related to multiple objects in the destination table and an object in the destination table can be related to multiple objects in the origin table, the relationship cardinality is esriRelCardinalityManyToMany.

attributed

Indicates whether the relationship is attributed.

Values: true | false

composite

Indicates whether the relationship is composite.

Values: true | false

Request Parameters

ParameterDetails
f

The response format. The default response format is html.

Values: html | json

JSON Response Syntax

{"relationships": [{
 "id": <id>,
 "name": "<name>",
 "backwardPathLabel": "<backwardPathLabel>",
 "originLayerId": <originLayerId>,
 "originPrimaryKey": "<originPrimaryKey>",
 "forwardPathLabel": "<forwardPathLabel>",
 "destinationLayerId": <destinationLayerId>,
 "originForeignKey": "<originForeignKey>",
 "relationshipTableId": <relationshipTableId>,
 "destinationPrimaryKey": "<destinationPrimaryKey>",
 "destinationForeignKey": "<destinationForeignKey>",
 "rules": [
  {
   "ruleID": <ruleID>,
   "originSubtypeCode": <originSubtypeCode>,
   "originMinimumCardinality": <originMinimumCardinality>,
   "originMaximumCardinality": <originMaximumCardinality>,
   "destinationSubtypeCode": <destinationSubtypeCode>,
   "destinationMinimumCardinality": <destinationMinimumCardinality>,
   "destinationMaximumCardinality": <destinationMaximumCardinality>
  }
 ],
 "cardinality": "<cardinality>",
 "attributed": <true | false>,
 "composite": <true | false>
}]}

JSON Response Example

{"relationships": [{
 "id": 0,
 "name": "county_division",
 "backwardPathLabel": "belongs",
 "originLayerId": 0,
 "originPrimaryKey": "GlobalID",
 "forwardPathLabel": "has",
 "destinationLayerId": 2,
 "originForeignKey": "GlobalID_sor",
 "relationshipTableId": 3,
 "destinationPrimaryKey": "GlobalID",
 "destinationForeignKey": "GlobalID_des",
 "rules": [
  {
   "ruleID": 1,
   "originSubtypeCode": 1,
   "originMinimumCardinality": 0,
   "originMaximumCardinality": 2,
   "destinationSubtypeCode": 0,
   "destinationMinimumCardinality": 0,
   "destinationMaximumCardinality": 1
  },
  {
   "ruleID": 2,
   "originSubtypeCode": 2,
   "originMinimumCardinality": -1,
   "originMaximumCardinality": -1,
   "destinationSubtypeCode": 0,
   "destinationMinimumCardinality": -1,
   "destinationMaximumCardinality": -1
  }
 ],
 "cardinality": "esriRelCardinalityOneToMany",
 "attributed": false,
 "composite": true
}]}