realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

Setting the same RLMArray to a relationship drops the data

Open dimazen opened this issue 9 years ago • 2 comments

Not sure, how valid this case is but: Imagine object A with to-many relationship to B. Later during mapping I'm evaluating target value for that relationship based on network response. It appears, that there are no changes, so caller of merge routing simply performs -[RLMObject setValue:forKey:] with the same RLMArray as it was.

The result is quite unexpected: all relationship data is gone! It seems, that you're not expecting the same object for relationship in RLMAccessor

dimazen avatar Sep 13 '15 10:09 dimazen

Handling the simple case of of assigning a property to itself would be simple enough by just checking if the linkviews are the same, but making it robust in the face of wrapper objects and such would require copying the data out of the input object.

tgoyne avatar Sep 14 '15 14:09 tgoyne

@tgoyne not sure I'm doing it correctly, but decided to reuse existing RLMArray by calling addObject: Later I'm setting it to the relationship and it gets purged by code from RLMAccessor above.

I've fixed it already in my code, but assuming this to be a bug :)

dimazen avatar Sep 15 '15 07:09 dimazen