realm-swift: System of object results in duplicates
Goals
I am building a chat application. I want to not have duplicates of my objects
I have mainly 3 objects: a channel, a message and an entity. Both the channel and the message have an entity (the channel can have two)
The channel has a primary key, while the message does not (the message has 2 identifiers - a local one and one from the server. when the one from the server arrives, I nullify the temp one. This all means that the Message cannot have a primary key.
The problem comes when trying to set a primary key to the Entity class. It doesn’t let me, because if I try to add a message that has attached to it an Entity that already exists in the database (was added because a channel with that entity was added), it crashes.
Expected Results
Have a system that enables me to handle my case. Maybe a custom setter that I can override when adding an Entity to check if it exists already or not.
Actual Results
I got a lot of duplicated instances
Steps to Reproduce
Simple adds of objects
Code Sample
https://gist.github.com/danipralea/e6dc03acd3a8df0e4aeb331bec26d5c8
Version of Realm and Tooling
Realm version: 2.1.2
Xcode version: 8.2
iOS/OSX version: 9.0
Dependency manager + version: 1.2.0.beta.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 33 (14 by maintainers)
I still have to implement the other suggestion of Dmitry. I will get back to you guys as soon as I do that.
Thank you very much for taking such care in the issue/issues
@danipralea is this still unclear? Let us know if we can clarify this further.
Unfortunately without any code sample or reproduction case I can’t suggest anything 😦 Please use Xcode’s debugger to find the exact place where duplicated object is created.
Thank you for reaching out, @danipralea. I’m going to look into the problem you’re experiencing and find someone who will be able to help resolve it with you. In the meantime, we appreciate your patience. 😸