Update records with relations

In some situations it is possible to update records with relations, but in other situations updating records with relations is prohibited. Below you will find in which cases you are able to update records with relations and in which cases it is prohibited.

MANY_TO_ONE (BELONGS_TO)

Update related records is prohibited due to data consistency reasons. For instance, we cannot update an entity from dataset comments with its parent entity from dataset posts, but it perfectly works in opposite way (see ONE_TO_MANY example).


ONE_TO_MANY (HAS_MANY)

You can change any fields of related records except hidden/system fields, the primary keys of related records are required:

Request:

PUT

https://<your-app-id>.app.jexia.com/rest/<your-dataset>

Send your Jexia token along in the Authorization header:

"Authorization" : "<your-jexia-token>


Body:

[
  {
    "id": "PUT_HERE_POST_ID",
    "title": "Updated with JSON",
    "post": "JSON is better :)",
    "comments": [
      {
        "id": "PUT_HERE_RELATED_COMMENT_ID",
        "comment": "Yes! I like JSON!"
      }
    ]
  }
]

MANY_TO_MANY

The behavior in case of MANY_TO_MANY relation is different. Wecannot influencerelated records but we should provide them (at least only primary key) to associate existing records from two datasets:

Request:

PUT

https://<your-app-id>.app.jexia.com/rest/<your-dataset>

Send your Jexia token along in the Authorization header:

"Authorization" : "<your-jexia-token>

Body:

[
    {
        "id": "29b1f6a3-f421-4f5e-9f07-b0c4671b675e",
        "title": "My updated title",
        "keywords": [
            {
                "id": "436477e3-620b-4c79-828c-eafcefa4b9de"
            },
            {
                "id": "d5095467-3b10-484a-a9a0-ea4a2ad88d6b"
            }
        ]
    }
]

Important:

  • to associate a posts entity with a new keywords entity we should provide the ids for all previously attached entities, otherwise the relations will be lost
  • if you do not know about existing relations between entities and do not want to change them - omit "keywords" key and they will be untouched
  • in order to delete relations provide an empty array "keywords":[]