[RestKit ]Can't merge models with two different entities named ...

581 views
Skip to first unread message

andreas wagner

unread,
Aug 4, 2011, 4:04:50 AM8/4/11
to RestKit
Hello,

i have updated to RestKit 0.9.3 and get the following error "Can't
merge models with two different entities named ..." at:

objectManager.objectStore = [RKManagedObjectStore
objectStoreWithStoreFilename:databaseName
usingSeedDatabaseName:seedDatabaseName managedObjectModel:nil
delegate:self];

i followed the RestKit Twitter CoreData Example.

any ideas on that, why it's happening?
thanks in advance,
andy

Jeremy Ellison

unread,
Aug 4, 2011, 9:31:15 AM8/4/11
to res...@googlegroups.com
Andy,

Do you have a seed database? Is it possible that the seed database was
created against a slightly different object model? If you changed the
object model (added/removed models or properties) you probably need to
regenerate your seed data.

Cheers,
Jeremy

andreas wagner

unread,
Aug 4, 2011, 10:10:08 AM8/4/11
to RestKit
i did not have a seed database before the update to 0.9.3, but now i
included it.

when i'm building for the seed database, i get the same error...

Gregory Combs

unread,
Aug 5, 2011, 12:16:58 AM8/5/11
to res...@googlegroups.com
Sometimes during development and testing the data model and store that you have in your project doesn't get updated in the simulator and the device.  This might have nothing to do with what you're seeing, but I'd like you to try somethings....

In Xcode, perform a "Clean".
Then delete your app's build folder, to force a "super-clean" build.
Then delete the app in the simulator (or your device, wherever you're attempting to run this).
Now, finally, do a fresh build & debug to see if it's fixed.

andreas wagner

unread,
Aug 5, 2011, 7:40:40 AM8/5/11
to RestKit
thanks, but the "super-clean" didn't work as well ;)

i tried something different and now everything works fine, as it seems
up to now...
what i did was mentioned here:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOM.html

changing RKManagedObjectStore.m

Line 70:

if (nilOrManagedObjectModel == nil) {
// NOTE: allBundles permits Core Data setup in unit tests
nilOrManagedObjectModel = [NSManagedObjectModel
mergedModelFromBundles:[NSBundle allBundles]];
}

to:

if (nilOrManagedObjectModel == nil) {
// NOTE: allBundles permits Core Data setup in unit tests
NSString *modelPath = [[NSBundle mainBundle]
pathForResource:@"dataModel" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
nilOrManagedObjectModel = [[NSManagedObjectModel alloc]
initWithContentsOfURL:modelURL];
}

i don't know if that changes may cause some different problems, but
for now i can live with that, or is there a better way to do things?

Gregory Combs

unread,
Aug 5, 2011, 3:18:29 PM8/5/11
to res...@googlegroups.com
Ah that explains it, you're using a versioned data store collection/bundle (the "d" notation in the file name).

andreas wagner

unread,
Aug 8, 2011, 5:53:53 AM8/8/11
to RestKit
yes, i do have a versioned data model... so i'm fine to use my
solution or should i remove the versioned data model and just use one?

thanks a lot

Victor Kryukov

unread,
Aug 9, 2011, 3:15:56 PM8/9/11
to res...@googlegroups.com
btw, instead of deleting your app build folder manually, hold Option while selecting Product menu in Xcode. 'Clean' will turn into 'Clean Build Folder'.

andreas wagner

unread,
Aug 10, 2011, 2:46:35 AM8/10/11
to RestKit
thanks Victor!

another nice-to-know shortcut :)

Blake Watters

unread,
Aug 10, 2011, 10:59:44 PM8/10/11
to res...@googlegroups.com
Interesting. I made the switch to the allBundles recently so that the core data model would load when RestKit is used in a unit testing bundle. Wonder why you are getting issues...

-- 
Blake Watters
Sent with Sparrow

Rune Madsen

unread,
Sep 22, 2011, 4:45:05 PM9/22/11
to res...@googlegroups.com
I'm getting this exact error as well. I'm creating the NSPersistentStoreCoordinator in my app delegate. I have tried cleaning, re-building, etc. etc., but it gives me the error still. Any ideas?

Gregory Combs

unread,
Sep 23, 2011, 11:13:05 PM9/23/11
to res...@googlegroups.com
Let RestKit create the store?

Ray Fix

unread,
Dec 20, 2011, 1:41:48 AM12/20/11
to res...@googlegroups.com

FWIW, ran into the same issue.  None of the suggested solutions quite did the trick for me, but they were good clues.  It seems unit tests + certain migrations (not trivial ones adding new entities) provokes the issue.

My solution was to do the following. Does not require modification of the RestKit library (although at the time of this old email I don't know if the API here was available.)

  // Look for our managed object model in all of the bundles. (From the app
  // it is in the main bundle but not for unit tests.)
  NSString *modelPath = nil;
  for (NSBundle* bundle in [NSBundle allBundles])
  {
    modelPath = [bundle pathForResource:@"MyDataModelFilename" ofType:@"momd"];
    if (modelPath)
      break;
  }
  NSAssert(modelPath != nil, @"Could not find managed object model.");
  NSManagedObjectModel* mom = [[NSManagedObjectModel alloc
                               initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];

    

  objectManager.objectStore
    [RKManagedObjectStore objectStoreWithStoreFilename:_databaseFilename 
                                 usingSeedDatabaseName:nil 
                                    managedObjectModel:mom 
                                              delegate:nil];

Hope that helps someone.

Ray

Dragon Smith

unread,
Jan 9, 2013, 5:23:52 AM1/9/13
to res...@googlegroups.com

[RKManagedObjectSeeder objectSeederWithObjectManager:[RKObjectManager sharedManager]];

was the evil in my case. I just commented this code and all is working well now.

Blake Watters

unread,
Jan 9, 2013, 9:03:50 AM1/9/13
to res...@googlegroups.com
The can't merge models error indicates the use of a versioned Core Data model along with an attempt to use one of the mergedModel methods. It fails because merging the different versions in the same model results in conflicts. You instead need to explicitly load the model by URL (which is what we do in the RKTwitter and RKSearch Core Data examples).


--
 
 

Reply all
Reply to author
Forward
0 new messages