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

Support specifying objectSchema/classes to be stored in a Realm #1506

Closed
yasirmturk opened this issue Feb 15, 2015 · 14 comments
Closed

Support specifying objectSchema/classes to be stored in a Realm #1506

yasirmturk opened this issue Feb 15, 2015 · 14 comments

Comments

@yasirmturk
Copy link

i have created multiple realm DBs but it creates all classes in every realm..? how to specify a model class for a specific realm?

@segiddins
Copy link
Contributor

Right now, there is no way to only have certain classes in certain Realms (there will be database tables created for all of your RLMObject subclasses), but the overhead from those empty tables is negligible. I hope that helps!

@yasirmturk
Copy link
Author

this could be simpler than it looks ..may be something like .. [[RLMRealm defaultRealm] registerClasses:...];

@segiddins
Copy link
Contributor

@yasirmturk the issue with require a call like that is that it's counter-intuitive and makes the API harder to use and more confusing to read code that uses Realm. We've never really seen anyone report an issue with the tables that are created, even if they are not used. Do you have a particular reason why you think the ability to register classes would be necessary?

@yoshyosh
Copy link
Contributor

I think there is a github issue that describes hiding any empty tables so it will end up doing this automatically

@astigsen
Copy link
Contributor

astigsen commented Feb 16, 2015 via email

@alazier
Copy link
Contributor

alazier commented Feb 17, 2015

@yasirmturk you will be able to do what you are asking once we open up support for our dynamic interface. With the dynamic interface you can open a Realm providing a custom schema, which is basically just a list of the objects/properties stored in the Realm - so eventually you will be able to specify what objects each Realm should support each time it is opened. Not sure yet when we will get around to making this functionality public though.

@yasirmturk
Copy link
Author

@segiddins an overload for advanced users never hurts the beginners using intuitive solution.. another suggestion is to use the method which is specifying migration rules..
[RLMRealm setSchemaVersion:1 forRealmAtPath:realmPATH registerClasses:@[[Employee class], [Department class], ...] withMigrationBlock:^(RLMMigration *migration, NSUInteger oldSchemaVersion) { }];
i think that is simpler than the other solutions @alazier @yoshyosh .. @astigsen gave a good idea too..

@segiddins it is a real mess even if you have 3 realms each having 10 tables and you end up looking at 2 DBs with 30 tables each

@jpsim
Copy link
Contributor

jpsim commented Mar 3, 2015

I'd be in favor of allowing users define per-realm models. I think this functionality would be different (simpler) than providing an entire schema in the dynamic interface case.

Not having superfluous tables in a db means not having to migrate one realm because the model class for another has changed.

How about something similar to +[RLMRealm setEncryptionKey:forRealmsAtPath:] like +[RLMRealm registerModelClasses:forRealmsAtPath:] which needs to be called prior to accessing a realm at that path. Then we'd be able to filter the schema before assigning it to the realm here.

Changing which classes are registered for a path would require a migration. This will make it easy for us to support existing users who want to clean up their realm files.

@yasirmturk
Copy link
Author

+100

@alazier alazier changed the title multiple realms contain all classes Support specifying objectSchema/classes to be stored in a Realm Mar 24, 2015
@alazier
Copy link
Contributor

alazier commented Mar 24, 2015

We will likely add this once we add support for RealmConfiguration for Realm initialization

@yasirmturk
Copy link
Author

Great..and i assume it would handle the cleanup of existing Realm DBs in production too

@yasirmturk
Copy link
Author

there is another backdraw ..it requires to migrate all models even if i have added a property in one of my 3 realm models

@timanglade
Copy link
Contributor

This will be implemented as part of #1584

@timanglade timanglade removed the P3 label Apr 28, 2015
@yasirmturk
Copy link
Author

What about the cleanup? of older schema versions?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants