Search code examples
cocoacore-datainheritancemogenerator

Overriding insertInManagedObjectContext: will have no effects on child entities in mogenerator : why and how to do?


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 and ChildEntity ; of course, ParentEntity is the parent entity of ChildEntity.
  • Then, I override the insertInManagedObjectContext: of the ParentEntity.
  • 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.


Solution

  • 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.