Implemented by:
- EOEnterpriseObject
- EOCustomObject
- EOGenericRecord
- Package:
- com.apple.client.eocontrol
- com.apple.yellow.eocontrol
The EORelationshipManipulation interface builds on the basic EOKeyValueCoding interface to allow you to modify to-many relationship properties. EOCustomObject and EOGenericRecord provide default implementations of EORelationshipManipulation, which you rarely (if ever) need to override.
The primitive methods addObjectToPropertyWithKey and removeObjectFromPropertyWithKey add
and remove single objects from to-many relationship arrays. The
two other methods in the interface, addObjectToBothSidesOfRelationshipWithKey and removeObjectFromBothSidesOfRelationshipWithKey, are
implemented in terms of the two primitives to handle reciprocal
relationships. These methods find the inverse relationship to the
one identified by the specified key (if there is such an inverse relationship)
and use addObjectToPropertyWithKey
and removeObjectFromPropertyWithKey
to
alter both relationships, whether they're to-one or to-many.
The primitive methods check first for a method you might implement, addTo
Key or removeFrom
Key, invoking
that method if it's implemented, otherwise using the basic key-value
coding methods to do the work. Consequently, you rarely need to
provide your own implementations of EORelationshipManipulation.
Rather, you can provide relationship accessors (addTo
Key or removeFrom
Key)
whenever you need to implement custom business logic.
public abstract void
addObjectToBothSidesOfRelationshipWithKey
(
EORelationshipManipulation anObject,
String key)
This method also properly handles removing this
and anObject from
their previous relationship as needed. For example, if an Employee
object belongs to the Research department, invoking this method with
the Maintenance department removes the Employee from the Research
department as well as setting the Employee's department to Maintenance.
public abstract void
addObjectToPropertyWithKey
(
Object anObject,
String key)
addTo
Key.
If the receiver doesn't have such a method, this method gets the
property array using valueForKey and operates directly
on that. For a to-many relationship, this method adds anObject to
the array if it is not already in the array. For a to-one relationship,
this method replaces the previous value with anObject. public abstract void
removeObjectFromBothSidesOfRelationshipWithKey
(
EORelationshipManipulation anObject,
String key)
null
as
the value. For a to-many relationship, anObject is
removed using removeObjectFromPropertyWithKey.public abstract void
removeObjectFromPropertyWithKey
(
Object anObject,
String key)
removeFrom
Key
.
If the receiver doesn't have such a method, this method gets the
property array using valueForKey and operates directly
on that. For a to-many relationship, this method removes anObject from
the array. For a to-one relationship, this method replaces anObject with null
.