Tiger problem after modifying managed object model at runtime

  • I am modifying a managed object model at runtime after having merged
    it from separate .mom files (see also my earlier post "Core Data:
    Cross-Model Relationships").

    The modification is setting up a few relationships between the now
    merged models. It works all nice under Leopard, but fails under
    Tiger. The modifications are done under Tiger, too, as far as I
    checked it in the debugger. But when trying to create entities with
    the resulting model, I get an exception saying "<FCTableLineItem
    0x4f2210> setValue:forUndefinedKey:]: this class is not key value
    coding-compliant for the key usedByInvoiceItems." when trying to
    insertNewObjectForEntityForName for entity "TableLineItem":

    #0 in -[NSException raise]
    #1 in -[NSFaultHandler fulfillFault:withContext:]
    #2 in -[NSManagedObjectContext(_NSInternalAdditions)
    _insertObjectWithGlobalID:globalID:]
    #3 in -[NSManagedObjectContext insertObject:]
    #4 in -[NSManagedObject initWithEntity:insertIntoManagedObjectContext:]
    #5 in +[NSEntityDescription
    insertNewObjectForEntityForName:inManagedObjectContext:]
    #6 in createTableItem at DataGenerators.m:70

    "usedByInvoiceItems" is indeed one of the relationships which I add
    programmatically for "TableItem", which is the parent of
    "TableLineItem".

    Before getting to this point, I already used
    insertNewObjectForEntityForName successfully for another entity with
    an added relationship, but this time the relationship was added to
    the entity being inserted itself, not its parent (no parent in this
    case at all).

    Therefore I speculated that Tiger does not update some cache in a sub
    entity after the relationship has been added to the parent. I added
    the following code after adding the relationship to trigger
    rechecking the parent, but with no avail:

    NSArray* subentities = [entity subentities];
    if (subentities && [subentities count] > 0) {
      [entity setSubentities:[NSArray array]];
      [entity setSubentities:subentities];
    }

    Any work around would be appreciated.

    Best
    Kai
  • What I forgot to mention: The project is build with Xcode 3 against the Tiger SDK with Deployment Target set to 10.4.

    Ka

    > I am modifying a managed object model at runtime after having merged it from separate .mom files (see also my earlier post "Core Data: Cross-Model Relationships").
    >
    > The modification is setting up a few relationships between the now merged models. It works all nice under Leopard, but fails under Tiger. The modifications are done under Tiger, too, as far as I checked it in the debugger. But when trying to create entities with the resulting model, I get an exception saying "<FCTableLineItem 0x4f2210>  setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key usedByInvoiceItems." when trying to insertNewObjectForEntityForName for entity "TableLineItem":
    >
    > #0 in -[NSException raise]
    > #1 in -[NSFaultHandler fulfillFault:withContext:]
    > #2 in -[NSManagedObjectContext(_NSInternalAdditions) _insertObjectWithGlobalID:globalID:]
    > #3 in -[NSManagedObjectContext insertObject:]
    > #4 in -[NSManagedObject initWithEntity:insertIntoManagedObjectContext:]
    > #5 in +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:]
    > #6 in createTableItem at DataGenerators.m:70
    >
    > "usedByInvoiceItems" is indeed one of the relationships which I add programmatically for "TableItem", which is the parent of "TableLineItem".
    >
    > Before getting to this point, I already used insertNewObjectForEntityForName successfully for another entity with an added relationship, but this time the relationship was added to the entity being inserted itself, not its parent (no parent in this case at all).
    >
    > Therefore I speculated that Tiger does not update some cache in a sub entity after the relationship has been added to the parent. I added the following code after adding the relationship to trigger rechecking the parent, but with no avail:
    >
    > NSArray* subentities = [entity subentities];
    > if (subentities && [subentities count] > 0) {
    > [entity setSubentities:[NSArray array]];
    > [entity setSubentities:subentities];
    > }
    >
    > Any work around would be appreciated.
    >
    > Best
    > Kai
  • > I am modifying a managed object model at runtime after having merged
    > it from separate .mom files (see also
    > my earlier post "Core Data: Cross-Model Relationships").
    >
    > The modification is setting up a few relationships between the now
    > merged models. It works all nice under
    > Leopard, but fails under Tiger. The modifications are done under
    > Tiger, too, as far as I checked it in the
    > debugger. But when trying to create entities with the resulting
    > model, I get an exception saying
    > "<FCTableLineItem 0x4f2210>  setValue:forUndefinedKey:]: this class
    > is not key value coding-compliant for the
    > key usedByInvoiceItems." when trying to
    > insertNewObjectForEntityForName for entity "TableLineItem":

    On Tiger, during runtime modifications to the model, Core Data
    doesn't automatically add individual properties to subentities.  On
    Leopard, we make an effort to do so at the time to model is added to
    the NSPersistentStoreCoordinator.
    --

    -Ben
  • Hi Ben,

    thanks a lot, this solved the problem.

    Only, Leopard seems to add new properties to subentities immediately (that is, not deferred until the model is added to the NSPersistentStoreCoordinator).

    So now I recursively add new properties to subentities and simply stop if I find the property in a subentity already.

    Kai

    >> I am modifying a managed object model at runtime after having merged it from separate .mom files (see also
    >> my earlier post "Core Data: Cross-Model Relationships").
    >>
    >> The modification is setting up a few relationships between the now merged models. It works all nice under
    >> Leopard, but fails under Tiger. The modifications are done under Tiger, too, as far as I checked it in the
    >> debugger. But when trying to create entities with the resulting model, I get an exception saying
    >> "<FCTableLineItem 0x4f2210> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the
    >> key usedByInvoiceItems." when trying to insertNewObjectForEntityForName for entity "TableLineItem":
    >
    > On Tiger, during runtime modifications to the model, Core Data doesn't automatically add individual properties to subentities.  On Leopard, we make an effort to do so at the time to model is added to the NSPersistentStoreCoordinator.
    > --
    >
    > -Ben
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today