New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] On development branch, existing object instances are not updated even when primaryKeyAttribute is specified #612
Comments
What kind of primary key do you have and what does the JSON look like? We made some changes yesterday to alleviate bug reports of duplicate keys being created with the current development code and I added unit tests for string and integer primary keys. Obviously missing something in the test suite |
The unit tests and the RKTwitterCoreData example are showing the correct behavior with regards to updating existing entities. I could really use some additional information about your app's data model and JSON structure to help debug. Please advise. |
Understood. The primary key is an Integer64 / NSNumber - quite innocuous. The JSON structure (ignoring non-referential fields) is as follows: Array of: order
Example JSON structure (with non-referential fields removed): [{
"order": {
"id": 201,
"venue_id": 1,
"order_components": [{
"order_component": {
"id": 254,
"sku_id": 149,
}
},
{
"order_component": {
"id": 255,
"sku_id": 145,
}
}]
}
},
{
"order": {
"id": 202,
"venue_id": 1,
"order_components": [{
"order_component": {
"id": 256,
"sku_id": 144,
}
}]
}
}] The relevant parts of the RestKit mappings are as follows: // Order Key Mappings
[orderObjectMapping mapKeyPath:@"id" toAttribute:@"orderID"];
[orderObjectMapping mapKeyPath:@"venue_id" toAttribute:@"venueID"];
// Order Primary Key Declaration
orderObjectMapping.primaryKeyAttribute = @"orderID";
// Order Relationships
[orderObjectMapping mapKeyPath:@"order_components.order_component" toRelationship:@"orderComponents" withMapping:orderComponentObjectMapping serialize:YES];
[orderObjectMapping hasOne:@"venue" withMapping:venueObjectMapping];
[orderObjectMapping connectRelationship:@"venue" withObjectForPrimaryKeyAttribute:@"venueID"];
// Order Component Key Mappings
[orderComponentObjectMapping mapKeyPath:@"id" toAttribute:@"orderComponentID"];
[orderComponentObjectMapping mapKeyPath:@"sku_id" toAttribute:@"skuID"];
// Order Component Primary Key Declaration
orderComponentObjectMapping.primaryKeyAttribute = @"orderComponentID";
// Order Component Relationships
[orderComponentObjectMapping hasOne:@"sku" withMapping:skuObjectMapping];
[orderComponentObjectMapping connectRelationship:@"sku" withObjectForPrimaryKeyAttribute:@"skuID"]; FYI We're now sitting happily on the master branch with no plans to switch back to development. I'll try to run another test on the development branch though to confirm that the behaviour is still incorrect there. Blake - I don't think there are other relevant parts of the mappings, but if you would like to see them, they're contained within setupRestKitMappings in the FGDataUpdater class in my finger-iphone repository. I've temporarily added you as a collaborator. |
I've re-tested on the development branch and can confirm that the behaviour is still incorrect with the latest cut of development code. |
It looks like this is related to the fact that, at the top level, the JSON is an array of several Orders rather than a dictionary representing a single Order. The first Order in each received JSON is not duplicated - but all the other Orders within the same array are duplicated. |
Dave - Thanks for the follow-up. I will write a test using an array and see if I can reproduce. Also note that this issue is about the only thing gating the 0.9.4 release and that in short order development will be merged to master. I'll follow up again once I've thrown more tests at it. |
Hrm. Wrote a unit test using an array with key-path based mapping and a primary key for the outer object and the mapping worked as expected. I am cloning your project now to drill in further. |
Seeing this on the finger-iphone project:
|
…r than duplicated when mapping an array. refs #612
Dave - It looks like the example project provided by @alessandroorru is demonstrating your issue as well. I am going to try and debug it using this project and will update the issue so don't worry about updating finger_iphone for my purposes. |
Thanks Blake. Good luck getting the release out & let me know if you do need anything from me on Monday. Cheers, On 31 Mar 2012, at 13:34, Blake Wattersreply@reply.github.com wrote:
|
Aha. Just ran into this issue myself. Glad to know its not my code. Let me know if I can do anything to help. |
@blakewatters look at issue #611, trying your fix i discovered a similar problem, I did some research and I posted there my opinions |
…ngCache. refs #612 There are some issues with the current implementation of the RKInMemoryMappingCache that are allowing the creation of duplicated objects. This commit switches the default cacheStrategy to RKFetchRequestMappingCache. The primary key branch (#613) contains architecture improvements that allow for a robust fix to the issues in the memory based cache.
…ngCache. refs #612 There are some issues with the current implementation of the RKInMemoryMappingCache that are allowing the creation of duplicated objects. This commit switches the default cacheStrategy to RKFetchRequestMappingCache. The primary key branch (#613) contains architecture improvements that allow for a robust fix to the issues in the memory based cache.
… cache strategy classes to eliminate issues with duplicated objects. closes #611, #612, #613, #618 * NSEntityDescription is now aware of the primaryKeyAttribute. Can be configured via Interface Builder within Xcode or programatically. * Added findByPrimaryKey: interface to the Core Data extensions. * Relaxed dependencies on RKManagedObjectMapping across the system now that primaryKey is available without a reference to the mapping.
@alessandroorru, @sprynmr, @dave-thompson If you have a minute, a quick sanity check that your duplicate objects issues are resolved would be most helpful. You'll want to enable the in memory cache via: using the sources on the 0.10.0 release branch. |
A quick run through seems to confirm the fix. Will let you know if I see anything strange. |
@blakewatters I tried it quickly and it seems to work ;) Anyway, I'm going to try to use it in the application I'm writing, so I can give you a better feedback in the next days Thank you! |
All seems good now, thanks Blake! |
On the development branch, existing object instances are not updated even when primaryKeyAttribute is specified. (Behaviour is correct on master branch.)
In place of updating existing object instances, RestKit on the development branch creates new instances with identical primary keys.
The text was updated successfully, but these errors were encountered: