Skip to content

Commit

Permalink
Merge e2fea15 into 96e91df
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Mar 7, 2022
2 parents 96e91df + e2fea15 commit a294d1f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ x.x.x Release notes (yyyy-MM-dd)
* Support change notifications on query results. ([#208](https://github.com/realm/realm-dart/pull/208))
* Support change notifications on list collections. ([#261](https://github.com/realm/realm-dart/pull/261))
* Support change notifications on realm objects. ([#262](https://github.com/realm/realm-dart/pull/262))
* Added support checking if Realm lists and Realm objects are valid. ([#183](https://github.com/realm/realm-dart/pull/183))
* Added support for checking if realm lists and realm objects are valid. ([#183](https://github.com/realm/realm-dart/pull/183))
* Support query on lists of realm objects. ([#239](https://github.com/realm/realm-dart/pull/239))
* Added support for opening Realm in read-only mode. ([#260](https://github.com/realm/realm-dart/pull/260))
* Primary key fields no longer required to be `final` in data model classes ([#240](https://github.com/realm/realm-dart/pull/240))
* Added support for opening a realm in read-only mode. ([#260](https://github.com/realm/realm-dart/pull/260))
* Primary key fields no longer required to be `final` in data model classes. ([#240](https://github.com/realm/realm-dart/pull/240))
* List fields no longer required to be `final` in data model classes. ([#253](https://github.com/realm/realm-dart/pull/253))
* Added convenience method to delete all realm objects of a given type. ([#283](https://github.com/realm/realm-dart/pull/283))

### Compatibility
* Dart ^2.15 on Windows, MacOS and Linux
Expand Down
3 changes: 3 additions & 0 deletions lib/src/realm_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ class Realm {
final handle = realmCore.queryClass(this, metadata.class_.key, query, args);
return RealmResultsInternal.create<T>(handle, this);
}

/// Deletes all [RealmObject]s of type `T` from the `Realm`
void deleteAll<T extends RealmObject>() => deleteMany(all<T>());
}

class Scheduler {
Expand Down
19 changes: 19 additions & 0 deletions test/realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,25 @@ Future<void> main([List<String>? args]) async {
realm.close();
});

test('Realm deleteAll', () {
var config = Configuration([Team.schema, Person.schema]);
var realm = Realm(config);

final denmark = Team('Denmark', players: ['Arnesen', 'Laudrup', 'Mølby'].map(Person.new));
final argentina = Team('Argentina', players: [Person('Maradona')]);
realm.write(() => realm.addAll([denmark, argentina]));

expect(realm.all<Person>().length, 4);
expect(realm.all<Team>().length, 2);

realm.write(realm.deleteAll<Team>);

expect(realm.all<Person>().length, 4); // no cascading deletes
expect(realm.all<Team>().length, 0);

realm.close();
});

test('Realm adding objects graph', () {
var studentMichele = Student(1)
..name = "Michele Ernesto"
Expand Down

0 comments on commit a294d1f

Please sign in to comment.