diff --git a/example/bin/myapp.g.dart b/example/bin/myapp.g.dart index 4b81d0787..1984c9107 100644 --- a/example/bin/myapp.g.dart +++ b/example/bin/myapp.g.dart @@ -61,12 +61,14 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Car._); - return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ + return SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string), SchemaProperty('model', RealmPropertyType.string, optional: true), SchemaProperty('kilometers', RealmPropertyType.int, optional: true), SchemaProperty('owner', RealmPropertyType.object, - optional: true, linkTarget: 'Person'), + optional: true, + linkTarget: 'Person', + linkTargetSchema: () => Person.schema), ]); } } @@ -111,7 +113,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Person._); - return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ + return SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), ]); diff --git a/flutter/realm_flutter/example/lib/main.g.dart b/flutter/realm_flutter/example/lib/main.g.dart index ba6690288..a5bb536fc 100644 --- a/flutter/realm_flutter/example/lib/main.g.dart +++ b/flutter/realm_flutter/example/lib/main.g.dart @@ -61,12 +61,14 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Car._); - return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ + return SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string), SchemaProperty('model', RealmPropertyType.string, optional: true), SchemaProperty('kilometers', RealmPropertyType.int, optional: true), SchemaProperty('owner', RealmPropertyType.object, - optional: true, linkTarget: 'Person'), + optional: true, + linkTarget: 'Person', + linkTargetSchema: () => Person.schema), ]); } } @@ -111,7 +113,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Person._); - return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ + return SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('age', RealmPropertyType.int), ]); diff --git a/generator/lib/src/realm_model_info.dart b/generator/lib/src/realm_model_info.dart index 1d58c7831..914194c5a 100644 --- a/generator/lib/src/realm_model_info.dart +++ b/generator/lib/src/realm_model_info.dart @@ -114,19 +114,23 @@ class RealmModelInfo { yield 'static SchemaObject _initSchema() {'; { yield 'RealmObjectBase.registerFactory($name._);'; - yield "return const SchemaObject(ObjectType.${baseType.name}, $name, '$realmName', ["; + yield "return SchemaObject(ObjectType.${baseType.name}, $name, '$realmName', ["; { yield* fields.map((f) { final namedArgs = { - if (f.name != f.realmName) 'mapTo': f.realmName, + if (f.name != f.realmName) 'mapTo': "'${f.realmName}'", if (f.optional) 'optional': f.optional, if (f.isPrimaryKey) 'primaryKey': f.isPrimaryKey, if (f.indexType != null) 'indexType': f.indexType, - if (f.realmType == RealmPropertyType.object) 'linkTarget': f.basicRealmTypeName, + if (f.realmType == RealmPropertyType.object) ...{ + 'linkTarget': "'${f.basicRealmTypeName}'", + 'linkTargetSchema': '() => ${f.fieldElement.modelType.asNonNullable.basicMappedName}.schema', + }, if (f.realmType == RealmPropertyType.linkingObjects) ...{ - 'linkOriginProperty': f.linkOriginProperty!, + 'linkOriginProperty': "'${f.linkOriginProperty!}'", 'collectionType': RealmCollectionType.list, - 'linkTarget': f.basicRealmTypeName, + 'linkTarget': "'${f.basicRealmTypeName}'", + 'linkTargetSchema': '() => ${f.fieldElement.modelType.asNonNullable.basicMappedName}.schema', }, if (f.realmCollectionType != RealmCollectionType.none) 'collectionType': f.realmCollectionType, }; @@ -145,11 +149,7 @@ extension on Map { String toArgsString() { return () sync* { for (final e in entries) { - if (e.value is String) { - yield "${e.key}: '${e.value}'"; - } else { - yield '${e.key}: ${e.value}'; - } + yield '${e.key}: ${e.value}'; } }() .join(','); diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index c63242407..836c93fcc 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////////////////// import 'dart:async'; +import 'dart:collection'; import 'dart:ffi'; import 'dart:io'; @@ -109,16 +110,35 @@ abstract class Configuration implements Finalizable { static String defaultRealmPath = _path.join(defaultStoragePath, 'default.realm'); Configuration._( - this.schemaObjects, { + Iterable schemaObjects, { String? path, this.fifoFilesFallbackPath, this.encryptionKey, this.maxNumberOfActiveVersions, - }) { + }) : schemaObjects = _getRelatedSchemas(schemaObjects) { _validateEncryptionKey(encryptionKey); this.path = path ?? _path.join(_path.dirname(_defaultPath), _path.basename(defaultRealmName)); } + static HashSet _getRelatedSchemas(Iterable objects) { + final result = HashSet(); + + void addItemAndChildren(SchemaObject obj) { + if (result.add(obj)) { + final linkSchemas = obj.properties.map((e) => e.linkTargetSchema).where((e) => e != null).map((e) => e!); + for (final linkSchema in linkSchemas) { + addItemAndChildren(linkSchema()); + } + } + } + + for (final obj in objects) { + addItemAndChildren(obj); + } + + return result; + } + // allow inheritors to override the _defaultPath value String get _defaultPath => Configuration.defaultRealmPath; @@ -254,7 +274,7 @@ abstract class Configuration implements Finalizable { /// {@category Configuration} class LocalConfiguration extends Configuration { LocalConfiguration._( - super.schemaObjects, { + Iterable schemaObjects, { this.initialDataCallback, this.schemaVersion = 0, super.fifoFilesFallbackPath, @@ -266,7 +286,7 @@ class LocalConfiguration extends Configuration { this.migrationCallback, super.maxNumberOfActiveVersions, this.shouldDeleteIfMigrationNeeded = false, - }) : super._(); + }) : super._(schemaObjects); /// The schema version used to open the `Realm`. If omitted, the default value is `0`. /// @@ -356,7 +376,7 @@ class FlexibleSyncConfiguration extends Configuration { FlexibleSyncConfiguration._( this.user, - super.schemaObjects, { + Iterable schemaObjects, { super.fifoFilesFallbackPath, super.path, super.encryptionKey, @@ -364,7 +384,7 @@ class FlexibleSyncConfiguration extends Configuration { this.clientResetHandler = const RecoverOrDiscardUnsyncedChangesHandler(onManualResetFallback: _defaultClientResetHandler), super.maxNumberOfActiveVersions, this.shouldCompactCallback, - }) : super._(); + }) : super._(schemaObjects); @override String get _defaultPath => realmCore.getPathForUser(user); @@ -387,12 +407,12 @@ extension FlexibleSyncConfigurationInternal on FlexibleSyncConfiguration { /// {@category Configuration} class DisconnectedSyncConfiguration extends Configuration { DisconnectedSyncConfiguration._( - super.schemaObjects, { + Iterable schemaObjects, { required super.path, super.fifoFilesFallbackPath, super.encryptionKey, super.maxNumberOfActiveVersions, - }) : super._(); + }) : super._(schemaObjects); @override String get _defaultPath => _path.dirname(path); @@ -403,11 +423,11 @@ class DisconnectedSyncConfiguration extends Configuration { /// {@category Configuration} class InMemoryConfiguration extends Configuration { InMemoryConfiguration._( - super.schemaObjects, { + Iterable schemaObjects, { super.fifoFilesFallbackPath, super.path, super.maxNumberOfActiveVersions, - }) : super._(); + }) : super._(schemaObjects); } /// A collection of properties describing the underlying schema of a [RealmObjectBase]. @@ -428,6 +448,12 @@ class SchemaObject { /// Creates schema instance with object type and collection of object's properties. const SchemaObject(this.baseType, this.type, this.name, this.properties); + + @override + bool operator ==(Object other) => other is SchemaObject && other.type == type; + + @override + int get hashCode => type.hashCode; } /// Describes the complete set of classes which may be stored in a `Realm` @@ -455,7 +481,7 @@ class RealmSchema extends Iterable { /// @nodoc extension SchemaObjectInternal on SchemaObject { - bool get isGenericRealmObject => type == RealmObject || type == EmbeddedObject || type == RealmObjectBase; + bool get isGenericRealmObject => type == RealmObject || type == EmbeddedObject || type == RealmObjectBase || type == AsymmetricObject; } /// [ClientResetHandler] is triggered if the device and server cannot agree diff --git a/lib/src/realm_property.dart b/lib/src/realm_property.dart index e43ed48ca..95dd66138 100644 --- a/lib/src/realm_property.dart +++ b/lib/src/realm_property.dart @@ -55,6 +55,8 @@ class SchemaProperty { /// Indicates that the property should be persisted under a different name String get mapTo => _mapTo ?? name; + final SchemaObject Function()? linkTargetSchema; + /// @nodoc const SchemaProperty( this.name, @@ -66,5 +68,6 @@ class SchemaProperty { this.linkTarget, this.linkOriginProperty, this.collectionType = RealmCollectionType.none, + this.linkTargetSchema, }) : _mapTo = mapTo; } diff --git a/test/backlinks_test.g.dart b/test/backlinks_test.g.dart index 224698d8f..e60931f2e 100644 --- a/test/backlinks_test.g.dart +++ b/test/backlinks_test.g.dart @@ -58,12 +58,17 @@ class Source extends _Source with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Source._); - return const SchemaObject(ObjectType.realmObject, Source, 'Source', [ + return SchemaObject(ObjectType.realmObject, Source, 'Source', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('oneTarget', RealmPropertyType.object, - mapTo: 'et mål', optional: true, linkTarget: 'Target'), + mapTo: 'et mål', + optional: true, + linkTarget: 'Target', + linkTargetSchema: () => Target.schema), SchemaProperty('manyTargets', RealmPropertyType.object, - linkTarget: 'Target', collectionType: RealmCollectionType.list), + linkTarget: 'Target', + linkTargetSchema: () => Target.schema, + collectionType: RealmCollectionType.list), ]); } } @@ -127,16 +132,18 @@ class Target extends _Target with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Target._); - return const SchemaObject(ObjectType.realmObject, Target, 'Target', [ + return SchemaObject(ObjectType.realmObject, Target, 'Target', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('oneToMany', RealmPropertyType.linkingObjects, linkOriginProperty: 'et mål', collectionType: RealmCollectionType.list, - linkTarget: 'Source'), + linkTarget: 'Source', + linkTargetSchema: () => Source.schema), SchemaProperty('manyToMany', RealmPropertyType.linkingObjects, linkOriginProperty: 'manyTargets', collectionType: RealmCollectionType.list, - linkTarget: 'Source'), + linkTarget: 'Source', + linkTargetSchema: () => Source.schema), ]); } } diff --git a/test/configuration_test.dart b/test/configuration_test.dart index 94a3884b3..307cbd317 100644 --- a/test/configuration_test.dart +++ b/test/configuration_test.dart @@ -25,6 +25,13 @@ import '../lib/realm.dart'; import 'test.dart'; import '../flavor_helpers.dart'; +part 'configuration_test.g.dart'; + +@RealmModel() +class _LinkToClassInAnotherFile { + late List<$RemappedClass> listProperty; +} + Future main([List? args]) async { await setupTests(args); @@ -637,4 +644,14 @@ Future main([List? args]) async { realm.write(() => realm.add(Dog("Foxi2"))); expect(() => realm.write(() {}), throws("Number of active versions (3) in the Realm exceeded the limit of 2")); }); + + test('Configuration.local pulls transitive closure of schema', () { + final config = Configuration.local([Team.schema, LinkToClassInAnotherFile.schema]); + + expect(config.schemaObjects.length, 4); + expect(config.schemaObjects, contains(Team.schema)); + expect(config.schemaObjects, contains(Person.schema)); + expect(config.schemaObjects, contains(LinkToClassInAnotherFile.schema)); + expect(config.schemaObjects, contains(RemappedClass.schema)); + }); } diff --git a/test/configuration_test.g.dart b/test/configuration_test.g.dart new file mode 100644 index 000000000..44fb474c3 --- /dev/null +++ b/test/configuration_test.g.dart @@ -0,0 +1,49 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'configuration_test.dart'; + +// ************************************************************************** +// RealmObjectGenerator +// ************************************************************************** + +// ignore_for_file: type=lint +class LinkToClassInAnotherFile extends _LinkToClassInAnotherFile + with RealmEntity, RealmObjectBase, RealmObject { + LinkToClassInAnotherFile({ + Iterable listProperty = const [], + }) { + RealmObjectBase.set>( + this, 'listProperty', RealmList(listProperty)); + } + + LinkToClassInAnotherFile._(); + + @override + RealmList get listProperty => + RealmObjectBase.get(this, 'listProperty') + as RealmList; + @override + set listProperty(covariant RealmList value) => + throw RealmUnsupportedSetError(); + + @override + Stream> get changes => + RealmObjectBase.getChanges(this); + + @override + LinkToClassInAnotherFile freeze() => + RealmObjectBase.freezeObject(this); + + static SchemaObject get schema => _schema ??= _initSchema(); + static SchemaObject? _schema; + static SchemaObject _initSchema() { + RealmObjectBase.registerFactory(LinkToClassInAnotherFile._); + return SchemaObject(ObjectType.realmObject, LinkToClassInAnotherFile, + 'LinkToClassInAnotherFile', [ + SchemaProperty('listProperty', RealmPropertyType.object, + linkTarget: 'myRemappedClass', + linkTargetSchema: () => RemappedClass.schema, + collectionType: RealmCollectionType.list), + ]); + } +} diff --git a/test/geospatial_test.g.dart b/test/geospatial_test.g.dart index dfad1d134..a90c70002 100644 --- a/test/geospatial_test.g.dart +++ b/test/geospatial_test.g.dart @@ -48,7 +48,7 @@ class Location extends _Location static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Location._); - return const SchemaObject(ObjectType.embeddedObject, Location, 'Location', [ + return SchemaObject(ObjectType.embeddedObject, Location, 'Location', [ SchemaProperty('type', RealmPropertyType.string), SchemaProperty('coordinates', RealmPropertyType.double, collectionType: RealmCollectionType.list), @@ -92,11 +92,12 @@ class Restaurant extends _Restaurant static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Restaurant._); - return const SchemaObject( - ObjectType.realmObject, Restaurant, 'Restaurant', [ + return SchemaObject(ObjectType.realmObject, Restaurant, 'Restaurant', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('location', RealmPropertyType.object, - optional: true, linkTarget: 'Location'), + optional: true, + linkTarget: 'Location', + linkTargetSchema: () => Location.schema), ]); } } @@ -131,10 +132,11 @@ class LocationList extends _LocationList static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(LocationList._); - return const SchemaObject( - ObjectType.realmObject, LocationList, 'LocationList', [ + return SchemaObject(ObjectType.realmObject, LocationList, 'LocationList', [ SchemaProperty('locations', RealmPropertyType.object, - linkTarget: 'Location', collectionType: RealmCollectionType.list), + linkTarget: 'Location', + linkTargetSchema: () => Location.schema, + collectionType: RealmCollectionType.list), ]); } } diff --git a/test/indexed_test.g.dart b/test/indexed_test.g.dart index a29ad252b..0bcc816ef 100644 --- a/test/indexed_test.g.dart +++ b/test/indexed_test.g.dart @@ -71,8 +71,7 @@ class WithIndexes extends _WithIndexes static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(WithIndexes._); - return const SchemaObject( - ObjectType.realmObject, WithIndexes, 'WithIndexes', [ + return SchemaObject(ObjectType.realmObject, WithIndexes, 'WithIndexes', [ SchemaProperty('anInt', RealmPropertyType.int, indexType: RealmIndexType.regular), SchemaProperty('aBool', RealmPropertyType.bool, @@ -154,7 +153,7 @@ class NoIndexes extends _NoIndexes static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(NoIndexes._); - return const SchemaObject(ObjectType.realmObject, NoIndexes, 'NoIndexes', [ + return SchemaObject(ObjectType.realmObject, NoIndexes, 'NoIndexes', [ SchemaProperty('anInt', RealmPropertyType.int), SchemaProperty('aBool', RealmPropertyType.bool), SchemaProperty('string', RealmPropertyType.string), @@ -209,7 +208,7 @@ class ObjectWithFTSIndex extends _ObjectWithFTSIndex static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(ObjectWithFTSIndex._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, ObjectWithFTSIndex, 'ObjectWithFTSIndex', [ SchemaProperty('title', RealmPropertyType.string), SchemaProperty('summary', RealmPropertyType.string, diff --git a/test/migration_test.g.dart b/test/migration_test.g.dart index a7b35c72c..3991c9068 100644 --- a/test/migration_test.g.dart +++ b/test/migration_test.g.dart @@ -33,7 +33,7 @@ class PersonIntName extends _PersonIntName static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(PersonIntName._); - return const SchemaObject(ObjectType.realmObject, PersonIntName, 'Person', [ + return SchemaObject(ObjectType.realmObject, PersonIntName, 'Person', [ SchemaProperty('name', RealmPropertyType.int), ]); } @@ -74,7 +74,7 @@ class StudentV1 extends _StudentV1 static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(StudentV1._); - return const SchemaObject(ObjectType.realmObject, StudentV1, 'Student', [ + return SchemaObject(ObjectType.realmObject, StudentV1, 'Student', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('yearOfBirth', RealmPropertyType.int, optional: true), ]); @@ -116,8 +116,7 @@ class MyObjectWithTypo extends _MyObjectWithTypo static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(MyObjectWithTypo._); - return const SchemaObject( - ObjectType.realmObject, MyObjectWithTypo, 'MyObject', [ + return SchemaObject(ObjectType.realmObject, MyObjectWithTypo, 'MyObject', [ SchemaProperty('nmae', RealmPropertyType.string), SchemaProperty('vlaue', RealmPropertyType.int), ]); @@ -159,7 +158,7 @@ class MyObjectWithoutTypo extends _MyObjectWithoutTypo static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(MyObjectWithoutTypo._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, MyObjectWithoutTypo, 'MyObject', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('value', RealmPropertyType.int), @@ -195,7 +194,7 @@ class MyObjectWithoutValue extends _MyObjectWithoutValue static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(MyObjectWithoutValue._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, MyObjectWithoutValue, 'MyObject', [ SchemaProperty('name', RealmPropertyType.string), ]); diff --git a/test/realm_object_test.g.dart b/test/realm_object_test.g.dart index 8e77e81b9..44256e9dd 100644 --- a/test/realm_object_test.g.dart +++ b/test/realm_object_test.g.dart @@ -34,7 +34,7 @@ class ObjectIdPrimaryKey extends _ObjectIdPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(ObjectIdPrimaryKey._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, ObjectIdPrimaryKey, 'ObjectIdPrimaryKey', [ SchemaProperty('id', RealmPropertyType.objectid, primaryKey: true), ]); @@ -69,8 +69,8 @@ class NullableObjectIdPrimaryKey extends _NullableObjectIdPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(NullableObjectIdPrimaryKey._); - return const SchemaObject(ObjectType.realmObject, - NullableObjectIdPrimaryKey, 'NullableObjectIdPrimaryKey', [ + return SchemaObject(ObjectType.realmObject, NullableObjectIdPrimaryKey, + 'NullableObjectIdPrimaryKey', [ SchemaProperty('id', RealmPropertyType.objectid, optional: true, primaryKey: true), ]); @@ -104,7 +104,7 @@ class IntPrimaryKey extends _IntPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(IntPrimaryKey._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, IntPrimaryKey, 'IntPrimaryKey', [ SchemaProperty('id', RealmPropertyType.int, primaryKey: true), ]); @@ -139,7 +139,7 @@ class NullableIntPrimaryKey extends _NullableIntPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(NullableIntPrimaryKey._); - return const SchemaObject(ObjectType.realmObject, NullableIntPrimaryKey, + return SchemaObject(ObjectType.realmObject, NullableIntPrimaryKey, 'NullableIntPrimaryKey', [ SchemaProperty('id', RealmPropertyType.int, optional: true, primaryKey: true), @@ -175,7 +175,7 @@ class StringPrimaryKey extends _StringPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(StringPrimaryKey._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, StringPrimaryKey, 'StringPrimaryKey', [ SchemaProperty('id', RealmPropertyType.string, primaryKey: true), ]); @@ -210,7 +210,7 @@ class NullableStringPrimaryKey extends _NullableStringPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(NullableStringPrimaryKey._); - return const SchemaObject(ObjectType.realmObject, NullableStringPrimaryKey, + return SchemaObject(ObjectType.realmObject, NullableStringPrimaryKey, 'NullableStringPrimaryKey', [ SchemaProperty('id', RealmPropertyType.string, optional: true, primaryKey: true), @@ -245,7 +245,7 @@ class UuidPrimaryKey extends _UuidPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(UuidPrimaryKey._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, UuidPrimaryKey, 'UuidPrimaryKey', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), ]); @@ -280,7 +280,7 @@ class NullableUuidPrimaryKey extends _NullableUuidPrimaryKey static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(NullableUuidPrimaryKey._); - return const SchemaObject(ObjectType.realmObject, NullableUuidPrimaryKey, + return SchemaObject(ObjectType.realmObject, NullableUuidPrimaryKey, 'NullableUuidPrimaryKey', [ SchemaProperty('id', RealmPropertyType.uuid, optional: true, primaryKey: true), @@ -319,12 +319,13 @@ class RemappedFromAnotherFile extends _RemappedFromAnotherFile static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(RemappedFromAnotherFile._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, RemappedFromAnotherFile, 'class with spaces', [ SchemaProperty('linkToAnotherClass', RealmPropertyType.object, mapTo: 'property with spaces', optional: true, - linkTarget: 'myRemappedClass'), + linkTarget: 'myRemappedClass', + linkTargetSchema: () => RemappedClass.schema), ]); } } @@ -363,7 +364,7 @@ class BoolValue extends _BoolValue static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(BoolValue._); - return const SchemaObject(ObjectType.realmObject, BoolValue, 'BoolValue', [ + return SchemaObject(ObjectType.realmObject, BoolValue, 'BoolValue', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), SchemaProperty('value', RealmPropertyType.bool), ]); diff --git a/test/realm_set_test.g.dart b/test/realm_set_test.g.dart index c8ce0aaa1..7c54c4328 100644 --- a/test/realm_set_test.g.dart +++ b/test/realm_set_test.g.dart @@ -39,7 +39,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Car._); - return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ + return SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), SchemaProperty('color', RealmPropertyType.string, optional: true), ]); @@ -256,7 +256,7 @@ class TestRealmSets extends _TestRealmSets static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(TestRealmSets._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, TestRealmSets, 'TestRealmSets', [ SchemaProperty('key', RealmPropertyType.int, primaryKey: true), SchemaProperty('boolSet', RealmPropertyType.bool, @@ -276,7 +276,9 @@ class TestRealmSets extends _TestRealmSets SchemaProperty('mixedSet', RealmPropertyType.mixed, optional: true, collectionType: RealmCollectionType.set), SchemaProperty('objectsSet', RealmPropertyType.object, - linkTarget: 'Car', collectionType: RealmCollectionType.set), + linkTarget: 'Car', + linkTargetSchema: () => Car.schema, + collectionType: RealmCollectionType.set), SchemaProperty('binarySet', RealmPropertyType.binary, collectionType: RealmCollectionType.set), SchemaProperty('nullableBoolSet', RealmPropertyType.bool, diff --git a/test/realm_value_test.g.dart b/test/realm_value_test.g.dart index 0aaec8d53..f14affcbf 100644 --- a/test/realm_value_test.g.dart +++ b/test/realm_value_test.g.dart @@ -40,7 +40,7 @@ class TuckedIn extends _TuckedIn static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(TuckedIn._); - return const SchemaObject(ObjectType.embeddedObject, TuckedIn, 'TuckedIn', [ + return SchemaObject(ObjectType.embeddedObject, TuckedIn, 'TuckedIn', [ SchemaProperty('x', RealmPropertyType.int), ]); } @@ -84,8 +84,7 @@ class AnythingGoes extends _AnythingGoes static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(AnythingGoes._); - return const SchemaObject( - ObjectType.realmObject, AnythingGoes, 'AnythingGoes', [ + return SchemaObject(ObjectType.realmObject, AnythingGoes, 'AnythingGoes', [ SchemaProperty('oneAny', RealmPropertyType.mixed, optional: true, indexType: RealmIndexType.regular), SchemaProperty('manyAny', RealmPropertyType.mixed, @@ -127,7 +126,7 @@ class Stuff extends _Stuff with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Stuff._); - return const SchemaObject(ObjectType.realmObject, Stuff, 'Stuff', [ + return SchemaObject(ObjectType.realmObject, Stuff, 'Stuff', [ SchemaProperty('i', RealmPropertyType.int), ]); } diff --git a/test/test.g.dart b/test/test.g.dart index dce0ed1f4..f5016352b 100644 --- a/test/test.g.dart +++ b/test/test.g.dart @@ -32,7 +32,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Car._); - return const SchemaObject(ObjectType.realmObject, Car, 'Car', [ + return SchemaObject(ObjectType.realmObject, Car, 'Car', [ SchemaProperty('make', RealmPropertyType.string, primaryKey: true), ]); } @@ -64,7 +64,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Person._); - return const SchemaObject(ObjectType.realmObject, Person, 'Person', [ + return SchemaObject(ObjectType.realmObject, Person, 'Person', [ SchemaProperty('name', RealmPropertyType.string), ]); } @@ -111,11 +111,13 @@ class Dog extends _Dog with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Dog._); - return const SchemaObject(ObjectType.realmObject, Dog, 'Dog', [ + return SchemaObject(ObjectType.realmObject, Dog, 'Dog', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('age', RealmPropertyType.int, optional: true), SchemaProperty('owner', RealmPropertyType.object, - optional: true, linkTarget: 'Person'), + optional: true, + linkTarget: 'Person', + linkTargetSchema: () => Person.schema), ]); } } @@ -165,10 +167,12 @@ class Team extends _Team with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Team._); - return const SchemaObject(ObjectType.realmObject, Team, 'Team', [ + return SchemaObject(ObjectType.realmObject, Team, 'Team', [ SchemaProperty('name', RealmPropertyType.string), SchemaProperty('players', RealmPropertyType.object, - linkTarget: 'Person', collectionType: RealmCollectionType.list), + linkTarget: 'Person', + linkTargetSchema: () => Person.schema, + collectionType: RealmCollectionType.list), SchemaProperty('scores', RealmPropertyType.int, collectionType: RealmCollectionType.list), ]); @@ -224,12 +228,14 @@ class Student extends _Student with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Student._); - return const SchemaObject(ObjectType.realmObject, Student, 'Student', [ + return SchemaObject(ObjectType.realmObject, Student, 'Student', [ SchemaProperty('number', RealmPropertyType.int, primaryKey: true), SchemaProperty('name', RealmPropertyType.string, optional: true), SchemaProperty('yearOfBirth', RealmPropertyType.int, optional: true), SchemaProperty('school', RealmPropertyType.object, - optional: true, linkTarget: 'School'), + optional: true, + linkTarget: 'School', + linkTargetSchema: () => School.schema), ]); } } @@ -296,15 +302,21 @@ class School extends _School with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(School._); - return const SchemaObject(ObjectType.realmObject, School, 'School', [ + return SchemaObject(ObjectType.realmObject, School, 'School', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('city', RealmPropertyType.string, optional: true), SchemaProperty('students', RealmPropertyType.object, - linkTarget: 'Student', collectionType: RealmCollectionType.list), + linkTarget: 'Student', + linkTargetSchema: () => Student.schema, + collectionType: RealmCollectionType.list), SchemaProperty('branchOfSchool', RealmPropertyType.object, - optional: true, linkTarget: 'School'), + optional: true, + linkTarget: 'School', + linkTargetSchema: () => School.schema), SchemaProperty('branches', RealmPropertyType.object, - linkTarget: 'School', collectionType: RealmCollectionType.list), + linkTarget: 'School', + linkTargetSchema: () => School.schema, + collectionType: RealmCollectionType.list), ]); } } @@ -349,13 +361,14 @@ class RemappedClass extends $RemappedClass static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(RemappedClass._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, RemappedClass, 'myRemappedClass', [ SchemaProperty('remappedProperty', RealmPropertyType.string, mapTo: 'primitive_property'), SchemaProperty('listProperty', RealmPropertyType.object, mapTo: 'list-with-dashes', linkTarget: 'myRemappedClass', + linkTargetSchema: () => RemappedClass.schema, collectionType: RealmCollectionType.list), ]); } @@ -387,7 +400,7 @@ class Task extends _Task with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Task._); - return const SchemaObject(ObjectType.realmObject, Task, 'Task', [ + return SchemaObject(ObjectType.realmObject, Task, 'Task', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), ]); @@ -429,7 +442,7 @@ class Product extends _Product with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Product._); - return const SchemaObject(ObjectType.realmObject, Product, 'Product', [ + return SchemaObject(ObjectType.realmObject, Product, 'Product', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), SchemaProperty('name', RealmPropertyType.string, @@ -474,11 +487,13 @@ class Schedule extends _Schedule static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Schedule._); - return const SchemaObject(ObjectType.realmObject, Schedule, 'Schedule', [ + return SchemaObject(ObjectType.realmObject, Schedule, 'Schedule', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), SchemaProperty('tasks', RealmPropertyType.object, - linkTarget: 'Task', collectionType: RealmCollectionType.list), + linkTarget: 'Task', + linkTargetSchema: () => Task.schema, + collectionType: RealmCollectionType.list), ]); } } @@ -531,7 +546,7 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Foo._); - return const SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ + return SchemaObject(ObjectType.realmObject, Foo, 'Foo', [ SchemaProperty('requiredBinaryProp', RealmPropertyType.binary), SchemaProperty('defaultValueBinaryProp', RealmPropertyType.binary), SchemaProperty('nullableBinaryProp', RealmPropertyType.binary, @@ -716,7 +731,7 @@ class AllTypes extends _AllTypes static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(AllTypes._); - return const SchemaObject(ObjectType.realmObject, AllTypes, 'AllTypes', [ + return SchemaObject(ObjectType.realmObject, AllTypes, 'AllTypes', [ SchemaProperty('stringProp', RealmPropertyType.string), SchemaProperty('boolProp', RealmPropertyType.bool), SchemaProperty('dateProp', RealmPropertyType.timestamp), @@ -793,13 +808,16 @@ class LinksClass extends _LinksClass static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(LinksClass._); - return const SchemaObject( - ObjectType.realmObject, LinksClass, 'LinksClass', [ + return SchemaObject(ObjectType.realmObject, LinksClass, 'LinksClass', [ SchemaProperty('id', RealmPropertyType.uuid, primaryKey: true), SchemaProperty('link', RealmPropertyType.object, - optional: true, linkTarget: 'LinksClass'), + optional: true, + linkTarget: 'LinksClass', + linkTargetSchema: () => LinksClass.schema), SchemaProperty('list', RealmPropertyType.object, - linkTarget: 'LinksClass', collectionType: RealmCollectionType.list), + linkTarget: 'LinksClass', + linkTargetSchema: () => LinksClass.schema, + collectionType: RealmCollectionType.list), ]); } } @@ -986,7 +1004,7 @@ class AllCollections extends _AllCollections static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(AllCollections._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, AllCollections, 'AllCollections', [ SchemaProperty('strings', RealmPropertyType.string, collectionType: RealmCollectionType.list), @@ -1125,7 +1143,7 @@ class NullableTypes extends _NullableTypes static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(NullableTypes._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, NullableTypes, 'NullableTypes', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), @@ -1206,7 +1224,7 @@ class Event extends _Event with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Event._); - return const SchemaObject(ObjectType.realmObject, Event, 'Event', [ + return SchemaObject(ObjectType.realmObject, Event, 'Event', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), SchemaProperty('name', RealmPropertyType.string, @@ -1271,14 +1289,20 @@ class Party extends _Party with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Party._); - return const SchemaObject(ObjectType.realmObject, Party, 'Party', [ + return SchemaObject(ObjectType.realmObject, Party, 'Party', [ SchemaProperty('host', RealmPropertyType.object, - optional: true, linkTarget: 'Friend'), + optional: true, + linkTarget: 'Friend', + linkTargetSchema: () => Friend.schema), SchemaProperty('year', RealmPropertyType.int), SchemaProperty('guests', RealmPropertyType.object, - linkTarget: 'Friend', collectionType: RealmCollectionType.list), + linkTarget: 'Friend', + linkTargetSchema: () => Friend.schema, + collectionType: RealmCollectionType.list), SchemaProperty('previous', RealmPropertyType.object, - optional: true, linkTarget: 'Party'), + optional: true, + linkTarget: 'Party', + linkTargetSchema: () => Party.schema), ]); } } @@ -1342,13 +1366,17 @@ class Friend extends _Friend with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Friend._); - return const SchemaObject(ObjectType.realmObject, Friend, 'Friend', [ + return SchemaObject(ObjectType.realmObject, Friend, 'Friend', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('age', RealmPropertyType.int), SchemaProperty('bestFriend', RealmPropertyType.object, - optional: true, linkTarget: 'Friend'), + optional: true, + linkTarget: 'Friend', + linkTargetSchema: () => Friend.schema), SchemaProperty('friends', RealmPropertyType.object, - linkTarget: 'Friend', collectionType: RealmCollectionType.list), + linkTarget: 'Friend', + linkTargetSchema: () => Friend.schema, + collectionType: RealmCollectionType.list), ]); } } @@ -1390,7 +1418,7 @@ class When extends _When with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(When._); - return const SchemaObject(ObjectType.realmObject, When, 'When', [ + return SchemaObject(ObjectType.realmObject, When, 'When', [ SchemaProperty('dateTimeUtc', RealmPropertyType.timestamp), SchemaProperty('locationName', RealmPropertyType.string), ]); @@ -1440,10 +1468,12 @@ class Player extends _Player with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Player._); - return const SchemaObject(ObjectType.realmObject, Player, 'Player', [ + return SchemaObject(ObjectType.realmObject, Player, 'Player', [ SchemaProperty('name', RealmPropertyType.string, primaryKey: true), SchemaProperty('game', RealmPropertyType.object, - optional: true, linkTarget: 'Game'), + optional: true, + linkTarget: 'Game', + linkTargetSchema: () => Game.schema), SchemaProperty('scoresByRound', RealmPropertyType.int, optional: true, collectionType: RealmCollectionType.list), ]); @@ -1479,9 +1509,11 @@ class Game extends _Game with RealmEntity, RealmObjectBase, RealmObject { static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Game._); - return const SchemaObject(ObjectType.realmObject, Game, 'Game', [ + return SchemaObject(ObjectType.realmObject, Game, 'Game', [ SchemaProperty('winnerByRound', RealmPropertyType.object, - linkTarget: 'Player', collectionType: RealmCollectionType.list), + linkTarget: 'Player', + linkTargetSchema: () => Player.schema, + collectionType: RealmCollectionType.list), ]); } } @@ -1722,7 +1754,7 @@ class AllTypesEmbedded extends _AllTypesEmbedded static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(AllTypesEmbedded._); - return const SchemaObject( + return SchemaObject( ObjectType.embeddedObject, AllTypesEmbedded, 'AllTypesEmbedded', [ SchemaProperty('stringProp', RealmPropertyType.string), SchemaProperty('boolProp', RealmPropertyType.bool), @@ -1846,20 +1878,26 @@ class ObjectWithEmbedded extends _ObjectWithEmbedded static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(ObjectWithEmbedded._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, ObjectWithEmbedded, 'ObjectWithEmbedded', [ SchemaProperty('id', RealmPropertyType.string, mapTo: '_id', primaryKey: true), SchemaProperty('differentiator', RealmPropertyType.uuid, optional: true), SchemaProperty('singleObject', RealmPropertyType.object, - optional: true, linkTarget: 'AllTypesEmbedded'), + optional: true, + linkTarget: 'AllTypesEmbedded', + linkTargetSchema: () => AllTypesEmbedded.schema), SchemaProperty('list', RealmPropertyType.object, linkTarget: 'AllTypesEmbedded', + linkTargetSchema: () => AllTypesEmbedded.schema, collectionType: RealmCollectionType.list), SchemaProperty('recursiveObject', RealmPropertyType.object, - optional: true, linkTarget: 'RecursiveEmbedded1'), + optional: true, + linkTarget: 'RecursiveEmbedded1', + linkTargetSchema: () => RecursiveEmbedded1.schema), SchemaProperty('recursiveList', RealmPropertyType.object, linkTarget: 'RecursiveEmbedded1', + linkTargetSchema: () => RecursiveEmbedded1.schema, collectionType: RealmCollectionType.list), ]); } @@ -1924,16 +1962,21 @@ class RecursiveEmbedded1 extends _RecursiveEmbedded1 static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(RecursiveEmbedded1._); - return const SchemaObject( + return SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded1, 'RecursiveEmbedded1', [ SchemaProperty('value', RealmPropertyType.string), SchemaProperty('child', RealmPropertyType.object, - optional: true, linkTarget: 'RecursiveEmbedded2'), + optional: true, + linkTarget: 'RecursiveEmbedded2', + linkTargetSchema: () => RecursiveEmbedded2.schema), SchemaProperty('children', RealmPropertyType.object, linkTarget: 'RecursiveEmbedded2', + linkTargetSchema: () => RecursiveEmbedded2.schema, collectionType: RealmCollectionType.list), SchemaProperty('realmObject', RealmPropertyType.object, - optional: true, linkTarget: 'ObjectWithEmbedded'), + optional: true, + linkTarget: 'ObjectWithEmbedded', + linkTargetSchema: () => ObjectWithEmbedded.schema), ]); } } @@ -1997,16 +2040,21 @@ class RecursiveEmbedded2 extends _RecursiveEmbedded2 static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(RecursiveEmbedded2._); - return const SchemaObject( + return SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded2, 'RecursiveEmbedded2', [ SchemaProperty('value', RealmPropertyType.string), SchemaProperty('child', RealmPropertyType.object, - optional: true, linkTarget: 'RecursiveEmbedded3'), + optional: true, + linkTarget: 'RecursiveEmbedded3', + linkTargetSchema: () => RecursiveEmbedded3.schema), SchemaProperty('children', RealmPropertyType.object, linkTarget: 'RecursiveEmbedded3', + linkTargetSchema: () => RecursiveEmbedded3.schema, collectionType: RealmCollectionType.list), SchemaProperty('realmObject', RealmPropertyType.object, - optional: true, linkTarget: 'ObjectWithEmbedded'), + optional: true, + linkTarget: 'ObjectWithEmbedded', + linkTargetSchema: () => ObjectWithEmbedded.schema), ]); } } @@ -2039,7 +2087,7 @@ class RecursiveEmbedded3 extends _RecursiveEmbedded3 static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(RecursiveEmbedded3._); - return const SchemaObject( + return SchemaObject( ObjectType.embeddedObject, RecursiveEmbedded3, 'RecursiveEmbedded3', [ SchemaProperty('value', RealmPropertyType.string), ]); @@ -2084,7 +2132,7 @@ class ObjectWithDecimal extends _ObjectWithDecimal static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(ObjectWithDecimal._); - return const SchemaObject( + return SchemaObject( ObjectType.realmObject, ObjectWithDecimal, 'ObjectWithDecimal', [ SchemaProperty('decimal', RealmPropertyType.decimal128), SchemaProperty('nullableDecimal', RealmPropertyType.decimal128, @@ -2140,14 +2188,17 @@ class Asymmetric extends _Asymmetric static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Asymmetric._); - return const SchemaObject( - ObjectType.asymmetricObject, Asymmetric, 'Asymmetric', [ + return SchemaObject(ObjectType.asymmetricObject, Asymmetric, 'Asymmetric', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), SchemaProperty('symmetric', RealmPropertyType.object, - optional: true, linkTarget: 'Symmetric'), + optional: true, + linkTarget: 'Symmetric', + linkTargetSchema: () => Symmetric.schema), SchemaProperty('embeddedObjects', RealmPropertyType.object, - linkTarget: 'Embedded', collectionType: RealmCollectionType.list), + linkTarget: 'Embedded', + linkTargetSchema: () => Embedded.schema, + collectionType: RealmCollectionType.list), ]); } } @@ -2196,11 +2247,13 @@ class Embedded extends _Embedded static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Embedded._); - return const SchemaObject(ObjectType.embeddedObject, Embedded, 'Embedded', [ + return SchemaObject(ObjectType.embeddedObject, Embedded, 'Embedded', [ SchemaProperty('value', RealmPropertyType.int), SchemaProperty('any', RealmPropertyType.mixed, optional: true), SchemaProperty('symmetric', RealmPropertyType.object, - optional: true, linkTarget: 'Symmetric'), + optional: true, + linkTarget: 'Symmetric', + linkTargetSchema: () => Symmetric.schema), ]); } } @@ -2232,7 +2285,7 @@ class Symmetric extends _Symmetric static SchemaObject? _schema; static SchemaObject _initSchema() { RealmObjectBase.registerFactory(Symmetric._); - return const SchemaObject(ObjectType.realmObject, Symmetric, 'Symmetric', [ + return SchemaObject(ObjectType.realmObject, Symmetric, 'Symmetric', [ SchemaProperty('id', RealmPropertyType.objectid, mapTo: '_id', primaryKey: true), ]);