Re: Deletion Confusion
Re: Deletion Confusion
- Subject: Re: Deletion Confusion
- From: George Domurot <email@hidden>
- Date: Sat, 8 Jan 2005 09:53:09 -0800
You might want to try:
while(project.phases().count()>0)
ec.deleteObject(project.phases().objectAtIndex(0));
Your delete rules should take care of the Tasks and any other
references.
On Jan 8, 2005, at 8:27 AM, James Cicenia wrote:
Thanks.. I was tooo tired last night. Fresh today!
Thanks for the enlightenment. Temporarily meant:
in its current EditingContext so I can undo it for them.
I will experiment with: project.setPhases(new NSMutableArray());
Otherwise this seemed to work:
for(int i=0;i<project.phases().count();i++){
ProjectPhase originalPhase =
(ProjectPhase)project.phases().objectAtIndex(i);
for(int j=0;j<originalPhase.tasks().count();j++){
ProjectPhaseTask originalTask = (ProjectPhaseTask)
originalPhase.tasks().objectAtIndex(j);
ec.deleteObject(originalTask);
}
ec.deleteObject(originalPhase);
}
Maybe I just need to loop through phases as my owns destination and
cascade rules are all set properly.
OK - I forgot about not modifying a collection. Hmm, so why did the
above code work? Shouldn't project.phases().count()
decrease in value by one each time through?
- James
On Jan 7, 2005, at 8:30 PM, Chuck Hill wrote:
On Jan 7, 2005, at 1:55 PM, James Cicenia wrote:
Hello -
I am baffled, tired, or both.
Baffled usually follows tired pretty closely IME.
I have the following structure with the shown relationships:
Project -->> Phases -->>Tasks
I need to temporarily purge all Phases and Task.
Your use of the word 'temporarily' makes me uneasy. How do you
temporarily delete objects? Have you discovered object
reincarnation? :-P
Is there a simple one line that I am missing that will do this?
ec.deleteObject(project);
Which I suspect is not what you want to do.
Do I have to walk through both Phases and Tasks or is
Phases good enough because of the cascade rule?
Phases is good enough. If the Project ->> Phases relationship is set
to owns destination, then
project.setPhases(new NSMutableArray());
might do it in one line. I don't know if that will work, seems like
it should.
ALSO, when I was iterating over the relationship to delete
each object, the set total kept getting smaller so it would never
delete all the records. It would always leave two. I thought
enumerator
would solve that, but no go.
No. You can't modify a collection that you are enumerating. You
need to make a copy:
NSArray copyOfPhases = new NSArray(project.phases());
and enumerate that.
Any help would be great.. too tired to see what I am doing wrong
here.
Hope that helped.
Chuck
--
Practical WebObjects - a book for intermediate WebObjects developers
who want to increase their overall knowledge of WebObjects, or those
who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden