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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…