You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using FEMMapping as NSMapTable key leads to duplicated objects #96
Hi,
It new version, FEM uses FEMMapping instead entity name as before as NSMapTable key. When using recursive relationships and therefore different FEMMapping in child object and when processing child, it tries to get object from cache but since child mapping is different it can't get it and inserts new object.
Simple solution is I think just to use mapping.entityName as key.
Side note about why I rewrote code to use FEMMapping as a key instead of entityName and why we can't go back: initially I was planning to use the same prefetch code for the Realm extension. However later it turned out that no prefetch required for the Realm. So why I didn't move the code back? In the next version I'm planning to deprecate entityName, and to leave simply objectClass for all of the cases. Using class instead of the entityName gives me ability to cache setter implementations and to speed up deserialization.
And also, I know that we can't do much about it now, but I think it would be much nicer if there was bug fixes release before Realm support. We wanted to get temporary fix for #80 but had to include whole Realm support as well, which in the end it seems broke some of functionality.
Observation: @jcavar do you have an inverse relationship? It looks like that you're trying to map chat to the message that is already included into the chat property.
@jcavar what I meant by my observation is that you probably don't need nested Chat mapping, since Message already included into the Chat and by using inverse relationship CoreData will be able to set a correct chat value on the message object.
Activity
dimazen commentedon May 19, 2017
Can you share code of the mapping that you're using as well as some sample JSON, please?
dimazen commentedon May 19, 2017
Side note about why I rewrote code to use
FEMMappingas a key instead ofentityNameand why we can't go back: initially I was planning to use the same prefetch code for the Realm extension. However later it turned out that no prefetch required for the Realm. So why I didn't move the code back? In the next version I'm planning to deprecateentityName, and to leave simplyobjectClassfor all of the cases. Using class instead of theentityNamegives me ability to cache setter implementations and to speed up deserialization.jcavar commentedon May 19, 2017
Here is simplified version:
Chat:
Message:
JSON:
jcavar commentedon May 19, 2017
Sure,
objectClassshould be fine as well.jcavar commentedon May 19, 2017
And also, I know that we can't do much about it now, but I think it would be much nicer if there was bug fixes release before Realm support. We wanted to get temporary fix for #80 but had to include whole Realm support as well, which in the end it seems broke some of functionality.
dimazen commentedon May 19, 2017
Agree, that to rollout a bugfix release would be a better option. Anyway it is a little bit late.
dimazen commentedon May 19, 2017
I'll try to release a hotfix within 1.5 hours
dimazen commentedon May 19, 2017
Observation: @jcavar do you have an inverse relationship? It looks like that you're trying to map
chatto themessagethat is already included into thechatproperty.GH-96 Add Chat and Message mappings for recursive tests
GH-96 Add spec for chat + message recursive mapping
GH-96 Add spec for to-many chat messages
GH-96 Add to-one indirect recursive spec
GH-96 Add FEMRepresentationUtility spec
GH-96 Add uniquing identifier for Mapping
GH-96 Add tests for Mapping uniquing identifier
6 remaining items
GH-96 Add spec for to-many chat messages
GH-96 Add to-one indirect recursive spec
GH-96 Add FEMRepresentationUtility spec
GH-96 Add uniquing identifier for Mapping
GH-96 Add tests for Mapping uniquing identifier
GH-96 Replace MapTable for primary keys to Dictionary with unique id …
GH-96 Add spec for presented primary keys collecting
GH-96 Add spec for corelated mapping for cache
GH-96 Replace usage of MapTable by ObjectCache to Dictionary
dimazen commentedon May 20, 2017
@jcavar this issue has been fixed in the 1.2.1 release.
Available in both Carthage and Pods (don't forget to update your repo)!
jcavar commentedon May 20, 2017
@dimazen thank you, that was fast 👍
Yes, we have inverse relationship from message to chat.
dimazen commentedon May 20, 2017
@jcavar what I meant by my observation is that you probably don't need nested Chat mapping, since Message already included into the Chat and by using inverse relationship CoreData will be able to set a correct chat value on the message object.
In any case thanks for your report!
jcavar commentedon May 20, 2017
Yes, that is good point, but we have explicitly disabled inverse relationship in CoreData editor for some reason.
dimazen commentedon May 20, 2017
Got it. Good luck with your project 👍