0

So lets say we have Project and Task entities in kinvey, each entity is stored in it's own collection (projects and tasks). When saving this entities I defined 'relations' so I can access the tasks related to a project easily.

// Save the Project, and save its Task as separate entity.
var promise = $kinvey.DataStore.save('project', project, {
    relations : { task: 'tasks' }
});

That was easy and it's in the docs. But when deleting the task like this:

someService.deleteApplication = function(task){
            return $kinvey.DataStore.destroy('tasks', task._id);
        };

It does delete the item in tasks collection but an item in projects collection still holds a reference to the deleted task (In this case it says the project entity has 3 tasks (1 more than what it actually has) ).

how to overcome this ? is it in the docs?

Thanks!

code4jhon
  • 5,725
  • 9
  • 40
  • 60

1 Answers1

0

It does not seem super clear from the docs but it looks like you need to update the relations in project yourself. Fetch the project using DataStore.get. Then remove the that task from the task array, then update the project using DataStore.update.

If you need to find the projects that reference that task, you can construct a query using the relation - this is from the Relational Data, Fetching, Queries area.

Kinvey does not support queries that peer into a related object’s properties. However, you can construct queries to retrieve all entities that have a relationship to a specific entity. This is done by querying on the _id field of the reference.

jhoskins98
  • 114
  • 5