RestKit/RestKit — Issue #585: RKManagedObjectStore initWithStoreFilename "can't merge models with two different entities."
Author: jinyk
Created: 2012-03-07 14:16:00+00:00
State: open

When setting up setting up the managed object store with the object manager, eventually
RKManagedObjectStore initWithStoreFilename:inDirectory:usingSeedDatabaseName:managedObjectModel:delegate gets called. There:

```objective-c
...
if (nilOrManagedObjectModel == nil) {
nilOrManagedObjectModel = [NSManagedObjectModel mergedModelFromBundles:[NSBundle allBundles]];
}
...
```
Causes an error for me:

> Can't merge models with two different entities named 'EntityName'

According to [Core Data Programming Guide: Using a Managed Object Model](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOM.html) Instead of `mergedModelFromBundles:`, use `initWithContentsOfURL:` to initialize the model. So I replaced that line with:

```objective-c
NSString *withoutExtension = [[storeFilename componentsSeparatedByString:@"."] objectAtIndex:0];
NSString *modelPath = [[NSBundle mainBundle] pathForResource:withoutExtension ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
nilOrManagedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
```

Is `initWithContentsOfURL:` functionally equivalent to `mergedModelFromBundles:`? This seems to have resolved the issue for me, but I'm not sure what the implications are, which is why I'm submitting this.