Remove relationships from published services (deleteFromDefinition)

1007
6
10-10-2022 12:13 PM
JamesCrandall
MVP Frequent Contributor

ArcGIS Server 10.8

SDE Geodatabase Feature Classes

 

Is there any way to remove relationships on a published server via the REST admin page using deleteFromDefinition request?

Feature/Map service published with feature classes that participate in relationships persist thru to the published service.  I supposed we could create another set of the feature classes that do not have relationships to use for publishing, but it's not preferred and looking for alternatives.

I did make an attempt to run this from the deleteFromDefinition task of the feature service in question but it didn't delete them.

{"relationships" : [

  {

     "id" : 0

  },

  {

     "id" : 1

  },

  {

     "id" : 2

  },

  {

     "id" : 3

  },

  {

     "id" : 4

  },

  {

     "id" : 5

  }

]

}

 

Thanks!

0 Kudos
6 Replies
ChrisSeabrooke1
New Contributor III

I've done this by entering the json into the Delete definition Input box of the Feature layer, not the service. You have to delete from both origin and destination layers and you might have to delete each relationship separately, even from the same feature layer. Example json (replace the values in square brackets with your values):

{
"relationships": [
{
"id" : [relationshipID],
"name" : "[relationshipName]",
"relatedTableId" : [#],
"cardinality" : "[cardinality]",
"role" : "[esriRole]",
"keyField" : "[keyField]",
"composite" : [true/false]
}
]
}

JamesCrandall
MVP Frequent Contributor

Edit: Perhaps this lists the relationships...  "FeatureServer/relationships"

 

Do you know where can I locate the relationship info/details in the service layer (cardinality, role, keyField, etc)?  I can only see a basic list of the relationships for each of the service layers but I just get a basic list:

JamesCrandall_0-1665491834857.png

 

0 Kudos
ChrisSeabrooke1
New Contributor III

If you have administrative rights to the service, at the top right in the screen before yo select a layer/table, you'll see links to Admin and API Reference. Select Admin and then when you select the layer, scroll to the bottom, your options will have changed to include Add Definition, Update Definition and Delete from Definition. Select any and it will show you the complete json for the layer. You'll find the relationship json details there.

JamesCrandall
MVP Frequent Contributor

Much appreciated!  Will give that a go.

 

 

0 Kudos
BrianDiunizio_GISP
New Contributor II

@JamesCrandall I was able to return a {"success" = true} by passing in JSON similar to the following JSON example. This took me a couple attempts because the 'Delete From Layer Definition' text box on the 'Delete From Layer Definition' admin page displays ALL of the JSON relevant to the hosted feature layer selected (as it should). So to remove the "relationships" simply remove all the extra JSON parameters above and below this snippet. The bit that threw me off initially is that the remaining JSON must be closed in curly {} braces accompanied with the appropriate indentation after the beginning curly {.

 

{
 "relationships" : [
    {
      "id" : 1, 
      "name" : "example", 
      "relatedTableId" : 0, 
      "cardinality" : "esriRelCardinalityOneToMany", 
      "role" : "esriRelRoleOrigin", 
      "keyField" : "example", 
      "composite" : false
    }, 
    {
      "id" : 2, 
      "name" : "example", 
      "relatedTableId" : 0, 
      "cardinality" : "esriRelCardinalityOneToMany", 
      "role" : "esriRelRoleOrigin", 
      "keyField" : "example", 
      "composite" : false
    }, 
    {
      "id" : 4, 
      "name" : "example", 
      "relatedTableId" : 7, 
      "cardinality" : "esriRelCardinalityOneToOne", 
      "role" : "esriRelRoleDestination", 
      "keyField" : "example", 
      "composite" : false
    }
  ]
}

 

 

0 Kudos
mikAMD
by
Occasional Contributor II

Any update on this?

My problem is that I added two relationships with the exact same id.

For example:

 

relationships": [
        {
          "id": 8,
          "name": "relation_essences-arbres_essences",
          "relatedTableId": 7,
          "cardinality": "esriRelCardinalityOneToMany",
          "role": "esriRelRoleOrigin",
          "keyField": "essence_id",
          "composite": false
        },
        {
          "id": 8,
          "name": "relation_essences-arbres_essences",
          "relatedTableId": 7,
          "cardinality": "esriRelCardinalityOneToMany",
          "role": "esriRelRoleOrigin",
          "keyField": "essence_id",
          "composite": false
        }
      ]

 

 

I have tried to deleteFromDefinition with the REST API and also "manually" by removing it in the json through the admin web page.

When trying to delete from the feature service, I get a success response, however, the relationships are still present. When trying to delete from the feature layer, i get an "Not supported. Schema changes are not allowed for service - [service name]." error.

@BrianDiunizio_GISP, I have also tried your method with a successful response, but the relationships are still there when I refresh.

Any help on this? I'm prepared to remove all the relations and recreate them if necessary!
For info I'm on AGOL.

Thanks.