我有一个对象模型,有一个主键,我想用另一个主键来修复该对象,但是realm.io说"这个对象已经存在" 主键与第一个对象
不同 RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
ActivityTreeModel *originalActivity = [ActivityTreeModel objectForPrimaryKey:activityUuid];
ActivityTreeModel *cloneActivity = originalActivity;
NSString *primaryKey = [NSString stringWithFormat:@"%@+%@",[originalActivity uuid], executionUuid ];
@try {
cloneActivity.uuid = primaryKey;
cloneActivity.execution_uuid = executionUuid;
}
@catch (NSException *exception) {
NSLog(@"error de realm %@",exception);
}
@finally {
}
[ActivityTreeModel createOrUpdateInRealm:realm withValue:cloneActivity];
[realm commitWriteTransaction];
任何想法?
答案 0 :(得分:2)
创建一个新的ActivityTreeModel
对象:[[ActivityTreeModel alloc] init]
,然后将其所有属性设置为您要复制的属性,但使用不同的主键。