Skip to content

Commit

Permalink
asymmetric object allow non embedded links (#1402)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikola Irinchev <[email protected]>
  • Loading branch information
nielsenko and nirinchev authored Nov 1, 2023
1 parent ddd5ed3 commit 27742d2
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 59 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* `SyncClientError`, `SyncConnectionError`, `SyncSessionError`, `SyncWebSocketError`, `GeneralSyncError` - replaced by `SyncError`.
* `SyncClientErrorCode`, `SyncConnectionErrorCode`, `SyncSessionErrorCode`, `SyncWebSocketErrorCode`, `GeneralSyncErrorCode, SyncErrorCategory` - replaced by `SyncErrorCode`.
* Throw an exception if `File::unlock` has failed, in order to inform the SDK that we are likely hitting some limitation on the OS filesystem, instead of crashing the application and use the same file locking logic for all the platforms. (Core upgrade)
* Lift a restriction that prevents asymmetric objects from linking to non-embedded objects. ([#1403](https://github.com/realm/realm-dart/issues/1403))

### Fixed
* Fixed iteration after `skip` bug ([#1409](https://github.com/realm/realm-dart/issues/1409))
Expand All @@ -31,7 +32,7 @@
* Sync protocol version bumped to 10. (Core upgrade)
* Handle `badChangeset` error when printing changeset contents in debug. (Core upgrade)

* Using Core 13.20.1.
* Using Core 13.23.2.

## 1.5.0 (2023-09-18)

Expand Down
8 changes: 1 addition & 7 deletions generator/lib/src/class_element_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,11 @@ extension ClassElementEx on ClassElement {
}
}

// Check that asymmetric objects:
// 1) only have links to embedded objects.
// 2) have a primary key named _id.
// Check that asymmetric objects have a primary key named _id.
if (objectType == ObjectType.asymmetricObject) {
var hasPrimaryKey = false;
for (final field in mappedFields) {
final fieldElement = field.fieldElement;
final classElement = fieldElement.type.basicType.element as ClassElement;
if (field.type.basicType.isRealmModel && !classElement.thisType.isRealmModelOfType(ObjectType.embeddedObject)) {
throw RealmInvalidGenerationSourceError('Asymmetric objects cannot link to non-embedded objects', todo: '', element: fieldElement);
}
if (field.isPrimaryKey) {
hasPrimaryKey = true;
if (field.realmName != '_id') {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions test/asymmetric_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Future<void> main([List<String>? args]) async {
await realm.syncSession.waitForUpload();
});

baasTest('Asymmetric tricks to add non-embedded links', (config) async {
baasTest('Asymmetric add non-embedded links', (config) async {
final realm = await getIntegrationRealm(appConfig: config);

realm.subscriptions.update((mutableSubscriptions) {
Expand All @@ -68,8 +68,7 @@ Future<void> main([List<String>? args]) async {

realm.write(() {
final s = realm.add(Symmetric(ObjectId()));
// Since this shenanigan is allowed, I have opened a feature request to allow
// direct links on a symmetric objects. See https://github.com/realm/realm-core/issues/6976.
realm.ingest(Asymmetric(ObjectId(), symmetric: s));
realm.ingest(Asymmetric(ObjectId(), embeddedObjects: [Embedded(1, symmetric: s)]));
realm.ingest(Asymmetric(ObjectId(), embeddedObjects: [Embedded(1, any: RealmValue.from(s))]));
});
Expand Down
1 change: 1 addition & 0 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class _Asymmetric {
@MapTo('_id')
late ObjectId id;

_Symmetric? symmetric;
late List<_Embedded> embeddedObjects;
}

Expand Down
11 changes: 11 additions & 0 deletions test/test.g.dart

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

0 comments on commit 27742d2

Please sign in to comment.