Skip to content
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

Realm Lists are being destroyed by SyncEngine #179

Closed
jln19 opened this issue Dec 26, 2019 · 21 comments · Fixed by #206
Closed

Realm Lists are being destroyed by SyncEngine #179

jln19 opened this issue Dec 26, 2019 · 21 comments · Fixed by #206
Assignees

Comments

@jln19
Copy link

jln19 commented Dec 26, 2019

IceCream seems like an awesome solution to Realm/iCloud! I've got sync somewhat working. However I'm having a fatal issue.

In my situation I need Dogs to have the option to have more than one Owner. So in Realm:

Owner:
let dogList = List<Dog>()

Dog:
let owners = LinkingObjects(fromType: Owner.self, property: "dogList")

Everything works fine in Realm. When I create a new Dog, I do this:

        realm.add(dog)
        if let owners = owners {
            for owner in owners {
               owner.dogList.append(dog)
           }
        }

Once I add the code below code however, all of my dogs get removed from their owners.

syncEngine = SyncEngine(objects: [
        SyncObject<Owner>(),
        SyncObject<Dog>(),
        ])

The dogs are still visible in Realm Studio (they still exist in Realm), but their relationship to their owner(s) has been destroyed. All of my owners show zero objects in their dogList, whereas they had nonzero objects before SyncEngine runs. Do you know why this is happening? Again this only happens when I start the SyncEngine. If I comment that out, all of my relationships are maintained in subsequent app launches.

@jln19 jln19 changed the title Can't get List to save or sync Realm Lists are being destroyed by SyncEngine Dec 26, 2019
@phr85
Copy link

phr85 commented Dec 27, 2019

Hello @jln19
I'm facing exactly the same issue.

I had a look to the sample app and I saw they do linking via

let dogs = LinkingObjects(fromType: Dog.self, property: "owner")

I guess I will now try to change my relationship to this.

@phr85
Copy link

phr85 commented Dec 27, 2019

Looks like other people facing the same problem:

@phr85
Copy link

phr85 commented Dec 27, 2019

@jln19 yeah we have to use LinkingObjects. Lists are not yet supported yet.

@jln19
Copy link
Author

jln19 commented Dec 27, 2019

@phr85 that's unfortunate that Lists are still not supported. I'm not sure how I would use LinkingObjects, because owners can have more than one dog, but dogs can also have more than one owner in my case.

@jln19
Copy link
Author

jln19 commented Dec 27, 2019

I've also tried this as a hack:

func restoreRelationships() {
        let allDogs = realm.objects(Dog.self)
        for dog in allDogs {
            for owner in dog.owners {
                 try! realm.write {
                    owner.dogList.append(dog)
                }
            }
        }
    }

But sadly the inner for loop doesn't execute because the dog has no owners :(

I've also tried changing the sync order as mentioned on another thread. i.e:

SyncObject<Dog>(),
SyncObject<Owner>(),

But that didn't help either.
Would really love to hear from someone on the team about how to handle many-to-many relationships. I'm desperate to get this working.

@liambolling
Copy link

+1 for this, everything was going great until my lists weren't syncing

@jln19
Copy link
Author

jln19 commented Dec 30, 2019

Well this is unfortunate. I guess the options now are to pay $30/month and figure out the Realm server, or try to manually save a list of IDs and re-create the dogList every time a sync happens :(

@jln19
Copy link
Author

jln19 commented Dec 31, 2019

Update but still bad news. I thought I'd try storing a list of IDs from which I could restore the lost objects, like:

@objc dynamic var dogIdArray = [String]()

But that's not supported by Realm:

message String "Property dogIdArray is declared as Array<String>, which is not a supported managed Object property type. If it is not supposed to be a managed property, either add it toignoredProperties()or do not declare it as@objc dynamic. See https://realm.io/docs/swift/latest/api/Classes/Object.html for more information."

Realm doesn't support array primitives and says we must use Lists instead, but IceCream doesn't support Lists...

@harry-lynn-evans
Copy link

harry-lynn-evans commented Jan 8, 2020

+1 for this too, was also going fine but my lists are not syncing. Is there anyway to create a many-to-many relationship with IceCream?

@aehlke
Copy link

aehlke commented Jan 28, 2020

@jln19 I'm unclear on whether IceCream doesn't support Lists of primitives (List<String>).

Also you could try storing a CSV string of IDs.

@lkzhao
Copy link

lkzhao commented Feb 17, 2020

Looking from https://github.com/caiyue1993/IceCream/blob/master/IceCream/Classes/CKRecordConvertible.swift#L89

Looks like IceCream does support List, and List is not supported right now.
Wonder if List can be added by looping through the object Id similar to relationship.

@fstigre
Copy link

fstigre commented Jul 8, 2020

I encourage everyone to donate, the developer is currently trying to make List work with IceCream. Let's help him out by donating. Let's make IceCream better. Thanks.

@aehlke
Copy link

aehlke commented Jul 9, 2020

Just did - benefitting a lot from this library with my apps!

@kushsolitary
Copy link

Donated - thanks for the awesome work.

@caiyue1993
Copy link
Owner

caiyue1993 commented Sep 29, 2020

Hi guys, many thanks for the donation and it really helps 😄 And I've been working on the List support #206 (which contains Object subclass) for a while and happily it will reach our expectation very soon. Please hold on for one moment and you guys could check the feature/list-support branch if you are interested in the progress. I'll let you know when finishes.

Besides, as for this question

@jln19 I'm unclear on whether IceCream doesn't support Lists of primitives (List<String>).

Also you could try storing a CSV string of IDs.

IceCream has supported List of primitive types already since the early version

@kushsolitary
Copy link

@caiyue1993 I just tested the feature/list-support for my app, and it seems to be working great. Thank you for the awesome work you're doing.

@fstigre
Copy link

fstigre commented Oct 2, 2020

@kushsolitary - You didn't have any issues when deleting items from a List<>? I had some issues when deleting items, they only get deleted from CloudKit but not from the local Realm. Thanks.

@kushsolitary
Copy link

@kushsolitary - You didn't have any issues when deleting items from a List<>? I had some issues when deleting items, they only get deleted from CloudKit but not from the local Realm. Thanks.

You're right, I spoke too soon.

@kushsolitary
Copy link

Hello, is there any update on this?

@caiyue1993
Copy link
Owner

caiyue1993 commented Feb 8, 2021

Hi,
I don't know whether you guys are still sticking around, but I'd like to say that through #206 now IceCream has fully supported the Realm List in the latest 2.0.0 version. And I've tested it and it works pretty well. (And the delete issue has also been fixed cc @kushsolitary @fstigre )

Please refer to the README for the detailed usage. Better late than never, huh? Thank you guys still cause I've been too busy on my daily job. Just open the issue ticket if you encounter further problems.

@harry-lynn-evans
Copy link

harry-lynn-evans commented Mar 12, 2022

@caiyue1993 - thanks for all your hard work, Ice Cream is awesome!!

IceCream has supported List of primitive types already since the early version

This doesn't work for me. I would like to store a List<Int?>(), however this doesn't appear in my CloudKit schema.

My project has:

class Dog: Object {
@objc dynamic var name: String = ""
@objc dynamic var uniqueID = NSUUID().uuidString
var results = List<Int?>()
}

I this example, both name and uniqueID are stored in CloudKit, but results does not appear in the schema, and so is not saving.

Any idea why this is not saving? Has anyone been able to store List<Int?> before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants