I am using RestKit 0.10.3 to ask for new messages from my custom web service.
I have all objects and mappings working properly but I am facing an issue about the number of objects returned by a single request made to the server (a RKObjectLoader instance).
Suppose that I have a MessengerConversation object which has a conversationID property value equal to 1 and no MessengerMessage inside of it (that is an empty conversation).
Initially I had requested for five new messages from my custom web service:
GET /messenger/conversations/1/messages/?maxmsgcount=5
and it returned a JSON payload like:
{
"messages": [
{
"content": "A new message.",
"messageid": 10
},
{
"content": "A new message.",
"messageid": 9
},
{
"content": "A new message.",
"messageid": 8
},
{
"content": "A new message.",
"messageid": 7
},
{
"content": "A new message.",
"messageid": 6
}
]
}
At the moment, everything worked fine and the results could be accessed by the returned objects from a RKObjectLoader callback:
[objects count] == 5
But after requesting for older five messages to the same API, a not desired result is appearing:
GET /messenger/conversations/1/messages/?maxmsgcount=5&msgsbeforeid=6
returning a JSON payload like:
{
"messages": [
{
"content": "A new message.",
"messageid": 5
},
{
"content": "A new message.",
"messageid": 4
},
{
"content": "A new message.",
"messageid": 3
},
{
"content": "A new message.",
"messageid": 2
},
{
"content": "A new message.",
"messageid": 1
}
]
}
The problem is with the [objects count] which is now equal to 10 instead of 5 as the number of returned messages into the received JSON payload.
This way, it is impossible to track the biggest and the smallest message IDs from the latest returned JSON payload because the objects array contains all messages inside of the referenced conversation.
Printing description of objects:
<__NSArrayM 0xa720a40>(
<MessengerMessage: 0xa721560> (entity: MessengerMessage; id: 0xa7021c0 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p1> ; data: <fault>),
<MessengerMessage: 0x13360490> (entity: MessengerMessage; id: 0x133605a0 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p2> ; data: <fault>),
<MessengerMessage: 0x13360510> (entity: MessengerMessage; id: 0xa7023a0 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p3> ; data: <fault>),
<MessengerMessage: 0x13360550> (entity: MessengerMessage; id: 0xa7022b0 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p4> ; data: <fault>),
<MessengerMessage: 0xa720290> (entity: MessengerMessage; id: 0xa702080 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p5> ; data: <fault>),
<MessengerMessage: 0xa71ca40> (entity: MessengerMessage; id: 0x13360cf0 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p6> ; data: <fault>),
<MessengerMessage: 0x12f96c40> (entity: MessengerMessage; id: 0xa7023f0 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p7> ; data: <fault>),
<MessengerMessage: 0x133603c0> (entity: MessengerMessage; id: 0x13360b10 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p8> ; data: <fault>),
<MessengerMessage: 0x13360380> (entity: MessengerMessage; id: 0x13360c00 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p9> ; data: <fault>),
<MessengerMessage: 0xa720700> (entity: MessengerMessage; id: 0x13360a20 <x-coredata://569C8DF6-D912-4DFF-B5A2-C462F0355B3F/MessengerMessage/p10> ; data: <fault>)
)
I am configuring all commented requests with the next settings due to mapping issues:
[objectManager loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader *loader) {
loader.targetObject = [MessengerConversation findByPrimaryKey:query.conversationID];
...
}];
Is it possible to make the RKObjectLoader to return only the objects mapped from latest received JSON payload?
I think I am missing something but I can't figure it out.
Thanks in advance.
Piva
primaryKeyAttributefor the mapper? - gdavisprimaryKeyAttribute. All mapping process was working properly, only the results were unexpected (it was returning all messages inside the conversation defined as thetargetObjectof the request). Updating the way I was inserting messages inside of conversations fixed my issue. - georgepiva