Re: willDelete() is not getting fired for children in a tree structured entity
Re: willDelete() is not getting fired for children in a tree structured entity
- Subject: Re: willDelete() is not getting fired for children in a tree structured entity
- From: Chuck Hill <email@hidden>
- Date: Mon, 26 Jul 2010 10:28:28 -0700
On Jul 24, 2010, at 1:51 AM, Farrukh Ijaz wrote:
> Thanks Chuck and Ramsey for quick response.
>
> I don't know what was the case. Whether the editingContexts where overlapping or not. Before I was using:
>
> a.delete();
> editingContext().saveChanges(); // This is the same editing context which was used to load "a".
>
> The above was not triggering willDelete() of children.
>
> I changed this with:
>
> editingContext().deleteObject(a);
> editingContext().saveChanges();
>
> This triggered willDelete() of children.
That seems unlikely to me. a.delete() is just a convenience:
public void delete() {
editingContext().deleteObject(this);
}
Something else changed.
> I also heard that if an entity has multiple levels of hierarchy then delete cascade won't work after second level.
I have not heard that. I have deleted several levels with no problems.
> a.toB().toC().toD()
>
> With willDelete() implemented and "editingContext().deleteObject(a)" will delete a and a.toB().
>
> If above is true, what is the best practice to complete the delete cascade?
If it does not work, then your model is wrong.
Chuck
> On 2010-07-23, at 11:07 PM, Ramsey Gurley wrote:
>
>>
>> On Jul 23, 2010, at 3:56 PM, Chuck Hill wrote:
>>
>>> willDelete() won't be called on the rest until saveChanges()
>>>
>>>
>>> On Jul 23, 2010, at 12:51 PM, Farrukh Ijaz wrote:
>>>
>>>> Hi,
>>>>
>>>> I have a model where an entity A has a recursive relationship as parent "toParentOfTypeA()" and children "toChildrenOfTypeA()". Consider it as a tree structured entity.
>>>>
>>>> In the model have setup the entity to delete cascade.
>>>>
>>>> In the entity I have overriden the method willDelete(). Now when I delete the parent, it fires the willDelete() of it but does not fire willDelete() of it's children. When I checked in the willDelete() I found the toChildren() relationship is empty but the children are there and I access it in the component when I generate tree.
>>
>>
>> I just wanted to add that if you are calling something like setParent instead of addObjectToBothSides that you will only be setting the relationship one way. So from your children, you will be able to see the toParent, but you will not see any children from the Parent's toChildren. There's a property to do this automatically in Wonder, but I think you need to be using wonder eogen templates for that property to work.
>>
>> If that isn't the case, then you may be crossing editing contexts.
>>
>> Ramsey
>>
>>
>>>> Below is the source code.
>>>>
>>>> Follwing method is overridden inside entity A.
>>>>
>>>> public void willDelete() {
>>>> ERXUtilities.deleteObjects(editingContext(), toChildrenOfTypeA());
>>>> }
>>>>
>>>> // below code is somewhere else.
>>>> A a = // object retrieved from the db.
>>>> a.delete();
>>>>
>>>> Any Idea? If needed, I can send the source code too.
>>>>
>>>> Farrukh
>>>>
>>>> Sent from my iPad _______________________________________________
>>>> 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
>>>
>>> --
>>> Chuck Hill Senior Consultant / VP Development
>>>
>>> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific 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:
>>>
>>> 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
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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