{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/1528","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1528/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1528/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1528/events","html_url":"https://github.com/realm/realm-cocoa/issues/1528","id":58224363,"number":1528,"title":"Migration on parent object changes - assert error","user":{"login":"MattKiazyk","id":1119565,"avatar_url":"https://avatars.githubusercontent.com/u/1119565?v=3","gravatar_id":"","url":"https://api.github.com/users/MattKiazyk","html_url":"https://github.com/MattKiazyk","followers_url":"https://api.github.com/users/MattKiazyk/followers","following_url":"https://api.github.com/users/MattKiazyk/following{/other_user}","gists_url":"https://api.github.com/users/MattKiazyk/gists{/gist_id}","starred_url":"https://api.github.com/users/MattKiazyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MattKiazyk/subscriptions","organizations_url":"https://api.github.com/users/MattKiazyk/orgs","repos_url":"https://api.github.com/users/MattKiazyk/repos","events_url":"https://api.github.com/users/MattKiazyk/events{/privacy}","received_events_url":"https://api.github.com/users/MattKiazyk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-cocoa/labels/pending","name":"pending","color":"ededed"}],"state":"closed","locked":false,"assignee":{"login":"jpsim","id":474794,"avatar_url":"https://avatars.githubusercontent.com/u/474794?v=3","gravatar_id":"","url":"https://api.github.com/users/jpsim","html_url":"https://github.com/jpsim","followers_url":"https://api.github.com/users/jpsim/followers","following_url":"https://api.github.com/users/jpsim/following{/other_user}","gists_url":"https://api.github.com/users/jpsim/gists{/gist_id}","starred_url":"https://api.github.com/users/jpsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpsim/subscriptions","organizations_url":"https://api.github.com/users/jpsim/orgs","repos_url":"https://api.github.com/users/jpsim/repos","events_url":"https://api.github.com/users/jpsim/events{/privacy}","received_events_url":"https://api.github.com/users/jpsim/received_events","type":"User","site_admin":false},"milestone":null,"comments":4,"created_at":"2015-02-19T15:40:18Z","updated_at":"2015-03-03T01:42:25Z","closed_at":"2015-03-03T01:42:25Z","body":"Currently I'm trying to add a new property called deleted on a parent RLMObject Class\r\n\r\n```\r\n@interface GTRemoteObject : RLMObject\r\n@property (assign, nonatomic) BOOL deleted;\r\n```\r\n\r\nI then have various subclasses inheriting from `GTRemoteObject`. I have a default value set on `GTRemoteObject` for deleted.\r\n\r\nMy migration is set to the following:\r\n\r\n```\r\n    [RLMRealm setSchemaVersion:1 forRealmAtPath:[RLMRealm defaultRealmPath]\r\n            withMigrationBlock:^(RLMMigration *migration, NSUInteger oldSchemaVersion) {\r\n        if (oldSchemaVersion < 1) {\r\n            [migration enumerateObjects:GTRemoteObject.className block:^(RLMObject *oldObject, RLMObject *newObject) {\r\n                newObject[@\"deleted\"] = @NO;\r\n            }];\r\n        }\r\n    }];\r\n```\r\nIt then will error out on the line:\r\n```\r\n// verify that we didn't add any properties twice due to inheritance\r\nassert(props.count == [NSSet setWithArray:[props valueForKey:@\"name\"]].count);\r\n```\r\nIf I remove the enumerate and just use a simple migration, same issue. If I set a migration for *every* subclass of `GTRemoteObject`, same error. I'm assuming this is because it's trying to add `deleted` to each subclass again, when I've already added it to the parent class in the migration?\r\n\r\nWhat am I missing? \r\n\r\nThanks\r\n\r\n-Matt"},"comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments/76870547","html_url":"https://github.com/realm/realm-cocoa/issues/1528#issuecomment-76870547","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1528","id":76870547,"user":{"login":"jpsim","id":474794,"avatar_url":"https://avatars.githubusercontent.com/u/474794?v=3","gravatar_id":"","url":"https://api.github.com/users/jpsim","html_url":"https://github.com/jpsim","followers_url":"https://api.github.com/users/jpsim/followers","following_url":"https://api.github.com/users/jpsim/following{/other_user}","gists_url":"https://api.github.com/users/jpsim/gists{/gist_id}","starred_url":"https://api.github.com/users/jpsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpsim/subscriptions","organizations_url":"https://api.github.com/users/jpsim/orgs","repos_url":"https://api.github.com/users/jpsim/repos","events_url":"https://api.github.com/users/jpsim/events{/privacy}","received_events_url":"https://api.github.com/users/jpsim/received_events","type":"User","site_admin":false},"created_at":"2015-03-03T01:42:25Z","updated_at":"2015-03-03T01:42:25Z","body":"Hi @MattKiazyk, have you made any progress on this?\r\n\r\nI think @segiddins is right in thinking that you're likely not setting an appropriate schema value.\r\n\r\nHere's some code I used to attempt to reproduce the behavior you're seeing:\r\n\r\n**First Run: Schema 0**\r\n```objc\r\n@interface ParentObject : RLMObject\r\n@property NSString *name;\r\n@end\r\n@implementation ParentObject\r\n@end\r\n\r\n@interface ChildObject : ParentObject\r\n@property NSInteger age;\r\n@end\r\n@implementation ChildObject\r\n@end\r\n\r\n// Later...\r\n\r\nRLMRealm *realm = [RLMRealm defaultRealm];\r\n[realm beginWriteTransaction];\r\n[ChildObject createInRealm:realm withObject:@[@\"child name\", @10]];\r\n[realm commitWriteTransaction];\r\n\r\nfor (ChildObject *obj in [ChildObject allObjects]) {\r\n  NSLog(@\"%@\", obj);\r\n}\r\n\r\n// Prints\r\n// \r\n// ChildObject {\r\n//     name = child name;\r\n//     age = 10;\r\n// }\r\n```\r\n\r\n**Second Run: Schema 1**\r\n```objc\r\n@interface ParentObject : RLMObject\r\n@property NSString *name;\r\n@property BOOL deleted;\r\n@end\r\n@implementation ParentObject\r\n@end\r\n\r\n@interface ChildObject : ParentObject\r\n@property NSInteger age;\r\n@end\r\n@implementation ChildObject\r\n@end\r\n\r\n// Later...\r\n\r\n[RLMRealm setDefaultRealmSchemaVersion:1\r\n                    withMigrationBlock:^(RLMMigration *migration, NSUInteger oldSchemaVersion) {\r\n    [migration enumerateObjects:@\"ParentObject\"\r\n                          block:^(RLMObject *oldObject, RLMObject *newObject) {\r\n        newObject[@\"deleted\"] = @NO;\r\n    }];\r\n    [migration enumerateObjects:@\"ChildObject\"\r\n                          block:^(RLMObject *oldObject, RLMObject *newObject) {\r\n        newObject[@\"deleted\"] = @NO;\r\n    }];\r\n}\r\nfor (ChildObject *obj in [ChildObject allObjects]) {\r\n  NSLog(@\"%@\", obj);\r\n}\r\n\r\n// Prints\r\n// \r\n// ChildObject {\r\n//     name = child name;\r\n//     age = 10;\r\n//     deleted = 0;\r\n// }\r\n```\r\n\r\nPlease reopen this issue if we've misunderstood the problem you're hitting. We'd greatly appreciate if you could send us code to reproduce the behavior if that's the case."}}