Visualize your collection as a table. Detaching an item is disconnecting a row from a table but leaving the data in the database to be used after of by another collection.
Records in a collection can be deleted or detached.
When you delete a record it will be removed form the collection and from the database.
When you detach a record it will be disconnected from the collection but it will stay in the database.
When a record is shared by two or more collections, we recommend detaching instead of removing.
If you detach an item (or record) you have three options:
•Detach all collection items: detaching all the items (records) of a collection is done using the detachAllCollectionItems function.
You only need to specify the Xpath to the collection and all the records will be detached.
•Detach some collection items: detaching some items (one or more records) of a collection is done using the detachCollectionItems function.
You need to specify the Xpath to the collection and the Xpath filtering the items you want to detach.
•Detach ONE collection item: detaching ONE item (record) of a collection is done using the detachCollectionItem function.
You need to specify the Xpath to the collection and the Xpath filtering the single item you want to detach. If more than one Xpath is found the function will present an error to the end user.
The functions are found in the Collection category.
The syntax of the functions is as follows:
Let's take a School process. Through the year the homeroom teacher is updating the student's grades and seeing who is approving and who is failing. There are three collections, the Student collection, with the updated information, the Approving collection and the Failing collection.
All of the are collections of the same Master entity: Students.
When the Students collection is updated, we want to detach from the Failing collections the ones whose average is now over 6 and another with the ones whose average is under 6.
We use the detachCollectionItems function to detach from the Failing list the students that are now approving.
We don't use the deleteCollectionItems function because we just want to disconnect the items from a collection, but still save them in the database, because they will be attached to the Approving collection, and are part of the main Students collection.
Below you will find the different ways that elements can be detached depending on the business requirement.
if(<count(School.Approvedstudents[Average < 6])>==1)
Me.detachCollectionItem("School.Approvedstudents", <School.Approvedstudents[Average < 6]>);
Detaches only one student whose average is below six and belongs to the Approved collection.
var average = 6;
Me.detachCollectionItems("School.Failedstudents", Me.getXPath("School.Students[Average > "+ average +"]"));
Me.detachCollectionItems("School.Failedstudents", <School.Students[Average > 6]>);
Detaches all students that were failing that now are approving. The items (students) will be disconnected from the Failing collection but will still be present in the data base.
Detaches all elements from both relationships, but now from the data base.