Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Manipulating Relationships

Enterprise Objects makes working with relationships rather simple. All you need is two enterprise objects in the same editing context to manipulate relationships programmatically. Were you to perform the same kind of task in other database development environments, you’d likely have to write many lines of SQL to relate a record in one table with a record in another table. With Enterprise Objects, however, a single method invocation does this for you.

Say you have an enterprise object representing a Document entity and a relationship in that entity called writers, which represents the authors of the document. To associate a new Writer record with the Document record, you simply create an enterprise object for the writer and then add it to the relationship with this code:

document.addObjectToBothSidesOfRelationshipWithKey(writer, "writers");

The first argument in the method invocation represents the Writer object. The second argument corresponds to the name of the relationship in the Document entity. If the relationship (in this case writers) is modeled with an inverse relationship, this method also adds the object to the other side of the relationship.

In addition to adding records in a relationship, you’ll likely also need to remove them. Fortunately, Enterprise Objects provides another method that does all the work for you:

document.removeObjectFromBothSidesOfRelationshipWithKey(writer, "writers");


< Previous PageNext Page > Hide TOC


Last updated: 2007-07-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice