2

我的 android 应用程序中有一些 realmObject(我的数据模型)和一些 Sync Realm,例如:

realm_url1 = "realm://myserver:9080/~/setting 包含一些用户设置 realmObject

realm_url2 = "realm://myserver:9080/~/app 包含一些应用领域对象

我如何设置在什么领域 URL 中创建的对象?因为我所有的realmObject 都在所有realm_url 中创建。我 getInstance 到 __permission 领域以读取用户权限,但我的所有领域对象都在那里创建并且 __permission 无法再次正常工作,我无法将其恢复到后面。请让我知道可以单独的对象是领域。

4

1 回答 1

1

如果你想为每个领域创建一个单独的模式,你可以通过使用@RealmModule注解来做到这一点。您可以在此处查看如何使用它:https ://realm.io/docs/java/latest/#schemas

// Create the module
@RealmModule(classes = { Person.class, Dog.class })
public class MyModule {
}

// Set the module in the RealmConfiguration to allow only classes defined by the module.
SyncConfiguration config = new SyncConfiguration.Builder(user, url)
  .modules(new MyModule())
  .build();

// It is possible to combine multiple modules to one schema.
SyncConfiguration config = new SyncConfiguration.Builder(user, url)
  .modules(new MyModule(), new MyOtherModule())
  .build();
于 2017-06-16T10:30:15.767 回答