Skip to content

Commit

Permalink
Convert getParent() to get parent
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Nov 3, 2022
1 parent d566a20 commit 931b376
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 11 additions & 1 deletion lib/src/realm_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ export "configuration.dart"
export 'credentials.dart' show Credentials, AuthProviderType, EmailPasswordAuthProvider;
export 'list.dart' show RealmList, RealmListOfObject, RealmListChanges;
export 'realm_object.dart'
show RealmEntity, RealmException, UserCallbackException, RealmObject, RealmObjectBase, EmbeddedObject, RealmObjectChanges, DynamicRealmObject;
show
RealmEntity,
RealmException,
UserCallbackException,
RealmObject,
RealmObjectBase,
EmbeddedObject,
EmbeddedObjectExtension,
RealmObjectChanges,
DynamicRealmObject;

export 'realm_property.dart';
export 'results.dart' show RealmResults, RealmResultsChanges, RealmResultsOfObject;
export 'session.dart' show Session, SessionState, ConnectionState, ProgressDirection, ProgressMode, SyncProgress, ConnectionStateChange;
Expand Down
9 changes: 6 additions & 3 deletions lib/src/realm_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ mixin RealmObjectBase on RealmEntity implements Finalizable {
}

/// @nodoc
static bool setDefaults<T extends RealmObject>(Map<String, Object> values) {
static bool setDefaults<T extends RealmObjectBase>(Map<String, Object> values) {
RealmAccessor.setDefaults<T>(values);
return true;
}
Expand Down Expand Up @@ -411,8 +411,11 @@ mixin RealmObjectBase on RealmEntity implements Finalizable {
mixin RealmObject on RealmObjectBase {}

/// @nodoc
mixin EmbeddedObject on RealmObjectBase {
RealmObjectBase? getParent() {
mixin EmbeddedObject on RealmObjectBase {}

extension EmbeddedObjectExtension on EmbeddedObject {
/// Retrieve the [parent] object of this embedded object.
RealmObjectBase? get parent {
if (!isManaged) {
return null;
}
Expand Down
12 changes: 6 additions & 6 deletions test/embedded_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,10 @@ Future<void> main([List<String>? args]) async {

final child1 = parent.recursiveObject!;

expect(child1.getParent(), parent);
expect(child1.child!.getParent(), child1);
expect(child1.parent, parent);
expect(child1.child!.parent, child1);

expect(parent.recursiveList[0].getParent(), parent);
expect(parent.recursiveList[0].parent, parent);
});

test('EmbeddedObject.getParent when unmanaged returns null', () async {
Expand All @@ -836,10 +836,10 @@ Future<void> main([List<String>? args]) async {

final child1 = parent.recursiveObject!;

expect(child1.getParent(), null);
expect(child1.child!.getParent(), null);
expect(child1.parent, null);
expect(child1.child!.parent, null);

expect(parent.recursiveList[0].getParent(), null);
expect(parent.recursiveList[0].parent, null);
});
}

Expand Down

0 comments on commit 931b376

Please sign in to comment.