# How to remove virtual relationships

**URL:** <https://community.dreamfactory.com/t/how-to-remove-virtual-relationships/3822>\
**Category:** Schema & Data\
**Created:** [May 12, 2017, 12:39am UTC](https://community.dreamfactory.com/t/how-to-remove-virtual-relationships/3822 "2017-05-12T00:39:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![filiptod](https://avatars.discourse-cdn.com/v4/letter/f/48db29/32.png) [@filiptod](https://community.dreamfactory.com/u/filiptod)\
**Post date:** [May 12, 2017, 12:39am UTC](https://community.dreamfactory.com/t/how-to-remove-virtual-relationships/3822/1 "2017-05-12T00:39:23Z")

</div>

Hi, I tried to test out adding virtual relationships between tables, but it seems I cannot remove a relationship once it’s set? I tried clicking on the relationship in the Relationships section in the Schema and have no option to delete it. If I change it in any way, I get an error “Syntax error or access violation: 1068 Multiple primary key defined…”, and when I click on the field itself, the Foreign and Virtual keys are already set so I cannot change or add multiple relationships.

So I have two questions, how do I remove virtual relationships and how do I add more than one relationship using the same field to reference different tables?

---

<div class="post-metadata">

**Author:** ![juniorconte](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/juniorconte/32/1007_2.png) [@juniorconte](https://community.dreamfactory.com/u/juniorconte)\
**Post date:** [May 20, 2017, 3:39am UTC](https://community.dreamfactory.com/t/how-to-remove-virtual-relationships/3822/2 "2017-05-20T03:39:17Z")

</div>

Hi @filiptod,

I think the best way for you to do this now is through the SQL REST API (API Docs)

```auto
DELETE /your-db-service/_schema/{table_name}/_related/{relationship_name}

```

You can also create new virtual relationships through the REST API.

```auto
POST /your-db-service/_schema/{table_name}/_related

{
  "resource": [
   {
      "alias": null,
      "name": "name_by_table_id",
      "label": "Name By Table Id",
      "description": null,
      "native": [],
      "type": "has_many",
      "field": "id",
      "is_virtual": true,
      "ref_service_id": 123,
      "ref_table": "name",
      "ref_field": "table_id",
      "ref_on_update": null,
      "ref_on_delete": null,
      "junction_service_id": null,
      "junction_table": null,
      "junction_field": null,
      "junction_ref_field": null,
      "always_fetch": false,
      "flatten": false,
      "flatten_drop_prefix": false
    }
  ]
}

```

You can also query all virtual and non-virtual relationships in a table.

```auto
GET /your-db-service/_schema/{table_name}/_related

```

best regards,  
Junior Conte

---

<div class="post-metadata">

**Author:** ![filiptod](https://avatars.discourse-cdn.com/v4/letter/f/48db29/32.png) [@filiptod](https://community.dreamfactory.com/u/filiptod)\
**Post date:** [May 23, 2017, 9:16pm UTC](https://community.dreamfactory.com/t/how-to-remove-virtual-relationships/3822/3 "2017-05-23T21:16:30Z")

</div>

Thank you very much for the reply! I went to the API Docs and all I seem to have access to is `DELETE /[my_service]/_schema/{table_name}/{field_name}`. There’s no API that adds a `_related/{relationship_name}`. I tried deleting the virtual relationship using its name as the `field_name`, it says it was successful but the relationship was still there, so that didn’t work. Could this be due to using an older version of Dreamfactory or some service that I don’t have?

---

<div class="post-metadata">

**Author:** ![juniorconte](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/juniorconte/32/1007_2.png) [@juniorconte](https://community.dreamfactory.com/u/juniorconte)\
**Post date:** [May 25, 2017, 11:29pm UTC](https://community.dreamfactory.com/t/how-to-remove-virtual-relationships/3822/4 "2017-05-25T23:29:25Z")

</div>

In my case, I did the tests with versions 2.4, 2.5 and 2.6.  
Which version are you using?

---

<div class="post-metadata">

**Author:** ![billionssg](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/billionssg/32/1107_2.png) [@billionssg](https://community.dreamfactory.com/u/billionssg)\
**Post date:** [January 1, 2018, 5:31pm UTC](https://community.dreamfactory.com/t/how-to-remove-virtual-relationships/3822/5 "2018-01-01T17:31:42Z")

</div>

any update for this issue? I experienced same problem here, cannot delete virtual relationship even from API Docs. It said success but nothing happened. I am using version 2.7.0
