Inserting/Deleting Records From Within EOGenericRecord
Inserting/Deleting Records From Within EOGenericRecord
- Subject: Inserting/Deleting Records From Within EOGenericRecord
- From: email@hidden
- Date: Tue, 09 Mar 2004 15:52:31 -0500
- Priority: normal
I am trying to insert and delete records from within an EOGenericRecord (or custom classes generated from the db schema of the EOModel)
First of all is this a good idea ? If its ok, then here is my problem.
When I try to delete a record related to the EOGenericRecord it SEEMS to have been deleted but its not.
To be specific, Subscriber is the EOGenericRecord and it has a one to many relationship with Subscription. (Subscriber<-(toSubscriptions)->>Subscription)
When I delete a subscription from subscriber by doing the following nothing happens:
this.removeFromToSubscriptions(subscription);
this.removeObjectFromBothSidesOfRelationshipWithKey(subscription,"toSubscriptions");
and then I actually delete the subscription record by calling the following generic method:
EOEditingContext ec = this.defaultEditingContext();
EODatabaseDataSource ds = new EODatabaseDataSource(ec,table);
WODisplayGroup genericDisplayGroup = new WODisplayGroup();
genericDisplayGroup.setDataSource(ds);
genericDisplayGroup.setObjectArray(new NSArray(record));
genericDisplayGroup.selectObject(record);
genericDisplayGroup.delete();
this.defaultEditingContext().saveChanges();
The above deletes the record from the database but when I print out "toSubscriptions" again there is the critter (and it hasn't been deleted from the "object graph"? or the relationship graph of the EOGenericRecord Subscriber).
No errors have popped up as of yet.
So I insert another subscription from within the same Subscriber.java as follows :
EOEditingContext ec = this.editingContext();
Subscription subscription = (Subscription)(EOClassDescription.classDescriptionForEntityName("Subscription")).createInstanceWithEditingContext(null,null);
subscription.setSubscriberId(this.subscriberId());
ec.insertObject(subscription);
ec.saveChanges();
Firstly am I right to use this editing context from the EOGenericRecord ?
As I insert another subscription from within the same subscriber it inserts ANOTHER subscription into the same subscriber and moves on until it hits the lines that ask it to save the changes :
ec.insertObject(subscription);
ec.saveChanges();
At this point it gives an error :
NSInvalidArgumentException: Exception while evaluating takeValue:forKeyPath:'child1.grade', on target:: *** -[NSConcreteMutableArray addObject:]: attempt to insert nil
Where child1 is another to-many relationship Subscriber.
What I don't understand is why a subscription record shows up in toSubscription() when I expressly delete it.
A. Shiraz
44 Executive Boulevard
Elmsford, NY 10523
(914) 592- 4203 x268
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.