Main Menu
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 6
Lecture 7
 

 

 

Adding an EO to a relationship

//existing sales person
SalesPerson sales;

//create a new client
Client newClient = ...;

//insert client into database
EOEditingContext ec = sales.editingContext();
ec.insertObject(newClient);

//relate client to salesperson
sales.addObjectToBothSidesOfRelatioshipWithKey(newClient, "clients");

addObjectToBothSidesOfRelatioshipWithKey performes different actions on different relationships

to-one - calls setVariable();

to-many - calls AddToVariables();

two-way - also sends setVariable() or addToVariable()

thus don't have to wory about whether object is one way or two way

Removing EOs from a relationship

//existing sales person and client
SalesPerson sales;
Client theClient;

//remove from salesperson's relationship sales
sales.removeObjectFromBothSidesOfRelatioshipWithKey(theClient, "clients");

//delete client from database 
EOEditingContext ec = theClient.editingContext(); 
ec.deleteObject(theClient); 
handles both one and two way relationships

Lect 5 Demo 4 and 5 ( Download 4 5)