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

RDART-996: Don't serialize backlinks #1617

Merged
merged 6 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Fixed
* Using valid const, but non-literal expressions, such as negation of numbers, as an initializer would fail. (Issue [#1606](https://github.com/realm/realm-dart/issues/1606))
* Backlinks mistakenly included in EJson serialization ([Issue #1616](https://github.com/realm/realm-dart/issues/1616))
elle-j marked this conversation as resolved.
Show resolved Hide resolved

### Compatibility
* Realm Studio: 13.0.0 or later.
Expand Down
17 changes: 17 additions & 0 deletions packages/realm_dart/test/backlinks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ void main() {
}
});

test('Backlinks not serialized', () {
final config = Configuration.local([Target.schema, Source.schema]);
final realm = getRealm(config);

final target = Target();
final source = realm.write(() => realm.add(Source(oneTarget: target)));

expect(() => source.toEJson(), returnsNormally); // <-- would die here before fix
expect(source.toEJson(), isNotNull);
expect(
source.toEJson(),
isA<Map<String, dynamic>>() //
.having((m) => m['et mål'], 'forward', isNotNull)
.having((m) => m['et mål']!['oneToMany'], 'back', isNull), // backlink not serialized
);
});

group('getBacklinks() tests', () {
(Target theOne, List<Target> targets, Iterable<String> expectedSources) populateData() {
final config = Configuration.local([Target.schema, Source.schema]);
Expand Down
4 changes: 0 additions & 4 deletions packages/realm_dart/test/backlinks_test.realm.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/realm_generator/lib/src/realm_model_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class RealmModelInfo {
{
yield 'return <String, dynamic>{';
{
yield* fields.map((f) {
yield* allSettable.map((f) {
return "'${f.realmName}': ${f.name}.toEJson(),";
});
}
Expand All @@ -115,7 +115,7 @@ class RealmModelInfo {
{
yield '{';
{
yield* fields.map((f) {
yield* allSettable.map((f) {
return "'${f.realmName}': EJsonValue ${f.name},";
});
}
Expand Down
elle-j marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject {
RealmObjectBase.registerFactory(Foo._);
register(_toEJson, _fromEJson);
return SchemaObject(ObjectType.realmObject, Foo, 'MyFoo', [
SchemaProperty('x', RealmPropertyType.int, indexType: RealmIndexType.regular),
SchemaProperty('x', RealmPropertyType.int,
indexType: RealmIndexType.regular),
SchemaProperty('bar', RealmPropertyType.object,
optional: true, linkTarget: 'Bar'),
]);
Expand Down Expand Up @@ -255,7 +256,6 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject {
'any': any.toEJson(),
'manyAny': manyAny.toEJson(),
'decimal': decimal.toEJson(),
'foos': foos.toEJson(),
};
}

Expand All @@ -279,7 +279,6 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject {
'any': EJsonValue any,
'manyAny': EJsonValue manyAny,
'decimal': EJsonValue decimal,
'foos': EJsonValue foos,
} =>
Bar(
fromEJson(name),
Expand Down
Loading