ios - Model a tree structure in Core Data -
i want implement multi-way tree using core data. there's "plan" entity in core data model.
plan / | \ plan plan plan / | \ | | \ plan plan ...
the plan of higher level have to-many relationship sub-plans.
so how should set relationship?
i define
- a to-many relationship
subplans
(orchildren
) plan entity itself, "delete rule" set "cascade", - a to-one relationship
superplan
(orparent
) plan entity itself, "delete rule" set "nullify", - and set these inverse relationships of each other.
if delete 1 plan object, automatically
- all sub-plans deleted due "cascade" delete rule, and
- the plan removed parent object due "nullify" delete rule.
Comments
Post a Comment