How to implement manage attaching and detaching nested relationships in OctoberCMS?

I looked at an example here for creating data using nested relationships, but I didn’t understand how to manage the attachment and detachment of nested relationship data.

How to create and make partials correctly in this case?

OctoberCMS version: 2.x (not 3.x)