RestKit 2.0:映射 - 当不唯一时,第二个entitiy nil [英] RestKit 2.0 : Mapping - second entitiy nil when not unique

查看:132
本文介绍了RestKit 2.0:映射 - 当不唯一时,第二个entitiy nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图映射一个注释数组到一个评论实体,它有一个子实体'testUser',写评论的人。只要所有注释的testUsers都是唯一的,一切正在映射。



如果用户写了两个注释,第二个注释将有一个nil testUser对象。 RestKit将第二个注释的testUser映射到与第一个testUser相同的对象,即使它们属于两个独立的注释对象。你可以在下面的映射结果中看到这一点。
我如何避免这种情况发生?



很多谢谢。



映射关系对象从keyPath'

用户'到'testUser'。
值:(entity:TestUser; id: 0x17e1a070 ; data:{

  =0x17e4d9b0  testFirstName = Sam; 
testID = 183599;
testLastName = Doe;

})



// 测试两个映射结果



映射关系对象从keyPath'user'到'testUser'。
值:(entity:TestUser; id: 0x17e1a070 ; data:{

  =0x15e72aa0  testFirstName = Sam; 
testID = 183599;
testLastName = Doe ;

})



strong>评论映射结果



2013-11-23 11:45:42.689应用[4619:8333] T restkit.object_mapping:RKMappingOperation.m:722将从keyPath'items'到items的 NSSet 关系对象映射。值:
{(



(实体:注释; ID:0x15eb9660; data:{

  commentId = 407381; 
createdAt =2013-11-23 10:45:13 +0000;
testUser =0x17e1a070& coredata:// 5038C2F2-93CF-46BF-BB2A-66F2423FA2DE / TestUser / p9>;

text =Test one;

}),

(实体:注释; id:0x17e4d9b0;
data:{

  commentId = 407382; 
createdAt =2013-11-23 10:45:30 +0000;
testUser = nil;
text =Test two;

})
)}



// 实体



> 评论(关系t0) - > TestUser

解决方案

em>您没有显示映射,我假设您有一对多的关系来支持您想要做的事情。



当创建关系映射时,您需要将 assignmentPolicy 属性设置为 RKUnionAssignmentPolicy 。默认策略会将任何现有连接替换为新连接。此政策将合并连接。


I am trying to map an array of 'Comments' to a Comment entity that has a sub-entity 'testUser', the person who wrote the comment. Everything is mapping fine as long as the testUsers for all comments are unique.

If a user writes two comments, the second comment will have a nil testUser object. RestKit is mapping the second comment's testUser to the same object as the first testUser, even they belong to two seperate comment-objects. You can see this in the mapping results below. How can I avoid this happening?

Many many thanks. Al

// Test one mapping result

Mapped relationship object from keyPath 'user' to 'testUser'. Value: (entity: TestUser; id: 0x17e1a070 ; data: {

comment = "0x17e4d9b0 <x-coredata:///Comment/tC0FCC2A0-6B2A-4130-A711-6E4A983D40F258>";
testFirstName = Sam;
testID = 183599;
testLastName = Doe;

})

// Test two mapping result

Mapped relationship object from keyPath 'user' to 'testUser'. Value: (entity: TestUser; id: 0x17e1a070 ; data: {

comment = "0x15e72aa0 <x-coredata://5038C2F2-93CF-46BF-BB2A-66F2423FA2DE/Comment/p46>";
testFirstName = Sam;
testID = 183599;
testLastName = Doe;

})

// Comments Mapping result

2013-11-23 11:45:42.689 app[4619:8333] T restkit.object_mapping:RKMappingOperation.m:722 Mapped NSSet relationship object from keyPath 'items' to 'items'. Value: {(

(entity: Comment; id: 0x15eb9660 ; data: {

commentId = 407381;
createdAt = "2013-11-23 10:45:13 +0000";
testUser = "0x17e1a070 <x-coredata://5038C2F2-93CF-46BF-BB2A-66F2423FA2DE/TestUser/p9>";

text = "Test one";

}), (entity: Comment; id: 0x17e4d9b0 ; data: {

commentId = 407382;
createdAt = "2013-11-23 10:45:30 +0000";
testUser = nil;
text = "Test two";

}) )}

// Entities

Commments (with relationship to)-> Comment (with relationship t0)-> TestUser

解决方案

You haven't shown mappings, and I'm assuming that you have a to-many relationship to support what you're trying to do.

When you create the relationship mapping you need to set the assignmentPolicy property to RKUnionAssignmentPolicy. The default policy replaces any existing connection with the new one. This policy will merge the connections instead.

这篇关于RestKit 2.0:映射 - 当不唯一时,第二个entitiy nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆