问题
In the methods insertInManagedObjectContext:
provided by mogenerator
, there is no call to any super methods.
I wonder why.
Indeed,
- Imagine I have two entities :
ParentEntity
andChildEntity
; of course,ParentEntity
is the parent entity ofChildEntity
. - Then, I override the
insertInManagedObjectContext:
of theParentEntity
. - But then, when I create a
ChildEntity
, none of my changes will be taken in account !!
I was wondering why such a choice and maybe a solution.
My need is to create a super entity with children and that this super entity have two insert methods. I want these two insert methods to be usable by the children.
回答1:
Probably they just didn't think of it the same way you do.
As for what you can do, why not implement your own method to take the place of insertInManagedObjectContext:
and have it call super's implementation? Generate the files, then put your new method in ChildEntity.m
, and have that version call super's version. You can't use the same method name since _ChildEntity.m
will have one that doesn't call super's version. So, use some other method name.
来源:https://stackoverflow.com/questions/16430005/overriding-insertinmanagedobjectcontext-will-have-no-effects-on-child-entities