Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem adding an entity to a to-many relationship



I am trying to get my head round Core Data and Bindings. I have created a simple core data model consisting of two entities called Course and Student. There is a to-many relationship from Course to Student. I have created a view with one table for Courses and another for students. There is a button for adding courses. That works fine. I also have a button which when clicked gets a CSV file containing student details. For each student in the file I want to create a new entity and have the following code in my NSPersistentDocument subclass:

NSManagedObjectContext *context = [self managedObjectContext];
Student *student = [NSEntityDescription insertNewObjectForEntityForName:@"Student" inManagedObjectContext:context];


This seems to work OK. I then update the fields with data from the CSV file.

The problem comes when I try to add the student to its owning course.

I get the course from the array controller using:

	Course *course = [[coursesController selectedObjects] objectAtIndex:0];

This seems to return the correct entity.

Then I then add the student using the predefined accessor:

	[course addStudentsObject:student];

This fails in the call [NSBinder _invokeSelector:withAguments:onKeyPath:ofObject:mode:raisesForNotApplicableKeys :]

I'm using the latest version of XCode and have got garbage collection switched on.

I hope someone can sort me out.

Cheers
Keith
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.