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

Relationships Must Be Marked As Optional #14

Closed
alekseyn opened this issue Jun 22, 2012 · 15 comments
Closed

Relationships Must Be Marked As Optional #14

alekseyn opened this issue Jun 22, 2012 · 15 comments
Assignees
Milestone

Comments

@alekseyn
Copy link

In order for Simperium to correct sync an object graph, relationships must always be marked as optional. This appears to be a requirement since entity data may arrive at the client in an undefined sequence. However, the client's own validation logic may require certain relationships to be properly indicated as mandatory.

It would be helpful for relationships to be defined as either optional or mandatory, as required by a specific application, and for simperium to sync correctly, regardless of whether or not relationships are marked as optional.

@mikejohnstn
Copy link
Contributor

Mandatory relationships should be working now.

@CapoChino
Copy link

@mikejohnstn, which branch(s) does your comment apply to? I'm using the 'master' branch and I'm having an issue that looks like "Relationships must be marked optional". Mine are not. Is that supported in master? Or do I need to upgrade to the 'develop' branch or mark my relationships optional? (Neither is a great option..) Thanks.

@jleandroperez
Copy link
Contributor

@CapoChino may i ask you what steps should i follow to reproduce the bug, and the problem you're seeing?.

Just in case, we've fixed a relationships-related glitch, in develop ("Upcoming 0.6.2 release"). #181

Thanks!

@CapoChino
Copy link

Hi Jorge,

I don't have an easy test case yet. I can create one if needed. But first, let's cover the basics:

My app has several relationships. Most are optional and have inverses. No many-to-many.
My app has custom NSManagedObject validation functions.
Here's a basic outline of the problem:

  1. I start with an empty database. The app programatically populates ~1500 objects (with relationships). They are saved and properly synced to Simperium.
  2. I quit the app and clear local data.
  3. I run the app again. Simperium tries to download the data, but fails with lots of Cocoa 1570 errors upon save. Upon inspecting the objects to save, I see that required relationships are 'nil', so Core Data is correct to reject the save.
  4. The relationships aren't nil on the cloud, so I suspected that Simperium was attempting to save at an improper point in the object graph reconstruction (i.e. this Issue Relationships Must Be Marked As Optional #14).
  5. I marked all relationships as Optional and tried again. This time, the 1570 errors were gone, but my custom validation functions failed for basically the same reason (nil relationships).
  6. I tried bypassing the validation, and tried again. This time, everything worked fine and the data was properly downloaded from the cloud and saved.

I found the problem happened the same on the 'develop' and 'master' branches.

I'd love to re-establish relationship requirements and object validation and still have Simperium work.

Do you already have a test case we can use for this? Basically, we want a large object graph (with mandatory relationships) in the cloud to be sync'd down to the device.

Thanks for your help and active contribution to this project!

Casey

@mikejohnstn mikejohnstn reopened this Dec 12, 2013
@mikejohnstn
Copy link
Contributor

I believe I was mistaken, come to think of it. We'll need to test and confirm. If they're still not working, I believe #121 is one possible solution.

@ghost ghost assigned jleandroperez Dec 12, 2013
@jleandroperez
Copy link
Contributor

@CapoChino sorry to hear you're having troubles!. May i ask you a couple questions regarding the data model?.

  • How many entities you have? (no need to enumerate the attributes)
  • Could you describe the relationships between them, and the settings on each?.

Basically, i'd love to recreate a data model resembling the one you're currently using, so we can replicate the exact same scenario.

Thanks in advance!

@CapoChino
Copy link

@jleandroperez,

I've uploaded a simplified version of my Xcode data model here:

https://www.dropbox.com/sh/k3jswiwophbj39s/XNhTVj9wPE

You can download this file and open in Xcode or include the model in a test project. Let me know if there's anything else I can provide.

Thank you,
Casey

@CapoChino
Copy link

Oh, also, @jleandroperez, I just wanted confirmation that you do expect mandatory relationships to work. It seems like Mike doesn't even expect them to work...

Thanks

@jleandroperez
Copy link
Contributor

@CapoChino thanks for posting the model!. I'll be building a sample app to replicate the issue.

Regarding whether if it should work or not, to be honest with you, so far i've been using optional relationships all along, since it gives you more flexibility (you can add EntityA, EntityB, and when needed, if needed, wire them together).

I'll take a look and get back to you soon!

@mikejohnstn
Copy link
Contributor

I'm suspecting the problem will arise for A --related--> B,when A arrives before B (asynchronously) and tries to save the context. Since the relationship is mandatory, A would be considered invalid until B is local and can be referenced via a managed object ID.

@jleandroperez
Copy link
Contributor

@CapoChino hey there!. I've been checking the issues you've been seeing.

Every entity managed by Simperium has its own "processor thread", where changes are applied (and saved using a temporary managedObjectContext), to provide a high level of parallelism, and significantly enhance speed.

As Mike pointed out, due to the asynchronous nature of the library, there is no way to warrantee that a group of objects will be transferred at the same time, which makes it impossible to safely set relationships before persisting to the store coordinator.

I'm afraid to say that, for the time being, mandatory relationships won't work correctly.

There might be a way around, though. The 'Embedded Entities' pull request should allow you to "embed" objects, one inside the other, so when they get transferred, you don't have to wait for anything else to go through the network: #121

We'll be working on merging that in the future. Sorry about any issues this might cause!

@CapoChino
Copy link

Well, that's unfortunate, especially since I was expecting them to work based on this thread. But it's not a deal-breaker. I may be able to ship my app with all relationships marked as optional in order to get the benefits of Simperuim. However, I'm having another problem with background NSManagedContexts. I'll address that in another issue.

Thanks for looking into this.

@jleandroperez jleandroperez modified the milestones: v0.7.1, v0.7.0 Feb 20, 2014
@danielr
Copy link

danielr commented Apr 30, 2014

Found this issue after running into exactly the same issue as @CapoChino. Seeing that your conversation took place 5 months ago: Are there any news on this? If not (that is, if optional relationships are still a requirement), I guess you should clearly state that in your documentation, since many people use mandatory relationships per default.

And: Thanks for your contributions to what seems to be an awesome project! :)

@jleandroperez
Copy link
Contributor

@danielr I'm sorry to say that, at least for the time being, there has been no progress on this front. We'll be updating the documentation shortly (#263).

Thanks for your feedback!

@jleandroperez
Copy link
Contributor

Closing in favor of Issue #442

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

No branches or pull requests

5 participants