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

Document shouldIncludeInDefaultSchema() #5707

Open
noamtamim opened this issue Mar 28, 2018 · 2 comments
Open

Document shouldIncludeInDefaultSchema() #5707

noamtamim opened this issue Mar 28, 2018 · 2 comments

Comments

@noamtamim
Copy link

noamtamim commented Mar 28, 2018

Also posted on SO, but no response so far.

My application uses two separate Realm instances (the second comes from a library).

The application itself uses Realm.Configuration.defaultConfuguration and the library creates its own configuration (Realm.Configuration(...)).

On runtime (after inspecting with Realm Browser), I see that both instances (each live in its own file) contain the models from both Realms. This, of course, has implications on migrations.

I know that when both use the same configuration we should set configuration.objectTypes, but I didn't expect it to matter when each instance has its own configuration.

How can two distinct configs share any data between them? It seems like a bug in Realm - or maybe I'm missing something.

@tgoyne
Copy link
Member

tgoyne commented Mar 28, 2018

By default objectTypes will include all RealmSwift.Object subclasses, regardless of where they are defined.

A library which uses Realm should override shouldIncludeInDefaultSchema() to exclude its types from the default objectTypes (i.e. add public override class func shouldIncludeInDefaultSchema() -> Bool { return false } to the class definitions) and then explicitly list the types it uses. This lets any applications using the library continue to simply use the automatic class discovery.

@noamtamim
Copy link
Author

Thank you @tgoyne. Can you please show me where all of this is documented, so I can make sure other similar issues are covered?

@bmunkholm bmunkholm changed the title Model leakage between two instances, each with own config Document shouldIncludeInDefaultSchema() Jul 12, 2018
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