我有一个包含两个对象的模型:SFCHChat
它们SFCHMessages
具有一对多的关系。
由于从 Realm 0.98 升级到 2.0,我现在在生产中遇到以下异常:
Migration is required due to the following errors: - Property 'SFCHChat.chatId' has been made optional. - Property 'SFCHChat.lastReadedMessageId' has been made optional. - Property 'SFCHMessage.chat' has been added. - Property 'SFCHMessage.messageId' has been made optional. - Property 'SFCHMessage.chatId' has been made optional. - Property 'SFCHMessage.userId' has been made optional. - Property 'SFCHMessage.message' has been made optional. - Property 'SFCHUser.initials' has been made optional. - Property 'SFCHUser.userId' has been made optional. - Property 'SFCHChat.messages' has been removed.
所以,我在 中添加了可选项+ (NSArray *)requiredProperties
,但不清楚如何处理SFCHChat.messages
和SFCHMessage.chat
。以下是这些对象的代码差异:
### SFCHMessage.h
-@property (readonly) SFCHChat *chat;
+@property SFCHChat *chat;
### SFCHMessage.m
-- (SFCHChat *)chat
-{
- return [[self linkingObjectsOfClass:@"SFCHChat" forProperty:@"messages"] firstObject];
-}
-
### SFCHChat.h
-@property RLMArray<SFCHMessage> *messages;
+@property (readonly) RLMLinkingObjects *messages;
### SFCHChat.m
++ (NSDictionary *)linkingObjectsProperties {
+ return @{
+ @"messages": [RLMPropertyDescriptor descriptorWithClass:SFCHMessage.class propertyName:@"chat"],
+ };
+}
+
总而言之,我将 Realm 对象上的数组迁移到RLMLinkingObjects
属性,因为linkingObjectsOfClass
已被弃用。因此,我没有向 RLMArray添加SFCHMessage
对象,而是向 each 添加了一个属性,并使用.SFCHChat.messages
chat
SFCHMessage
RLMLinkingObjects
看起来更改为(readonly)
被视为删除领域中的属性,而删除它被视为添加属性。我真的需要一个迁移块来处理我的案例吗?我将如何执行此迁移?