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

Unable to execute a migration that changes the "embeddedness" of an object #7060

Closed
nirinchev opened this issue Jan 20, 2021 · 6 comments
Closed

Comments

@nirinchev
Copy link
Member

nirinchev commented Jan 20, 2021

Goals

A user has reported on the forums that they would like to be able to migrate a model from Object to EmbeddedObject.

Expected Results

Migration function gets executed allowing them to ensure each object only has one parent, after which the "embeddedness" of the table changes and the model is now treated as embedded.

Actual Results

App crashes with Cannot convert object type ‘MyObject’ to embedded because objects have multiple incoming links*.. Based on a conversation with @jsflax and @tgoyne, it appears the reason is that the SDK eagerly changes the table to embedded before running the migration function, which then triggers a guard at Core that ensures that only one parent points to the child object.

Steps for others to Reproduce

Don't have exact steps, but seems like:

  1. Create a model as inheriting from Object.
  2. Have several other objects link to it.
  3. Bump schema version and modify your model to inherit from EmbeddedObject.

Version of Realm and Tooling

Realm framework version: 10.5.0

@sipersso
Copy link

Thanks for reporting the issue @nirinchev!

In this case, there is actually only one parent for each child object. So in step two, I think it is enough to have one object linking to it. If you need any more info from me, let me know here or in the forums.

@sipersso
Copy link

Just tried the doing the same migration on Android/Java and the migration works perfectly there using the same data models. So this seems to be an issue on iOS only.

@DominicFrei
Copy link
Contributor

Note about the difference:
The iOS SDK uses SchemaMode::Automatic whereas the Java SDK uses SchemaMode::Manual while migrating which leads to apply_pre_migration_changes not being executed on their side.
On the Java side the user takes care of all those migrations themselves (within the migration function).

@sipersso
Copy link

@DominicFrei What does this mean in practice? Does that mean that this migration won't be possible to do with the iOS SDK? Is there a way to run the iOS SDK using manual schema mode?

@DominicFrei
Copy link
Contributor

@sipersso I did have a longer conversation about this yesterday. We need to fix two things to make this work. So at the moment it actually does not which is a bug.
Regarding the mode: at the moment it is run in automatic and the iOS SDK does not offer manual since it's supposed to 'just work' with automatic which it will after the aforementioned bug fixes.

@DominicFrei
Copy link
Contributor

The relevant core changes have been released with Realm Cocoa 10.7.0.

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

No branches or pull requests

3 participants