Sunday, September 29, 2013

coredata 1 to many relationship

Use COREDATA, set two tables, company and department two tables. Want to set up a company in relation to more than one department, the company added a table relationship relationship named dept. And the relationship has been marked to-many relationship hook.

But when I do not know how to insert data to build up this relationship.

Insert the code below.

NSManagedObject * main = [NSEntityDescription insertNewObjectForEntityForName: @ "Company" inManagedObjectContext: self.managedObjectContext];
[Main setValue: @ "OK" forKey: @ "name"];

NSManagedObject * dpt1 = [NSEntityDescription insertNewObjectForEntityForName: @ "Department" inManagedObjectContext: self.managedObjectContext];
[Dpt1 setValue: @ "A" forKey: @ "deptName"];

NSManagedObject * dpt2 = [NSEntityDescription insertNewObjectForEntityForName: @ "Department" inManagedObjectContext: self.managedObjectContext];
[Dpt2 setValue: @ "B" forKey: @ "deptName"];

Insert the anomaly in the relationship. How does this relationship value assignment.
[Main setValue: dpt1 forKey: @ "dept"];


Establish a good table structure
company z_pk, z_ent, z_opt, zname
department z_pk, z_ent, z_opt, z3dept , zdeptname

But do not know how to set up two tables-many relationship. Still do not know how the value assigned z3dept.

Please expert guidance.

No comments:

Post a Comment