Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into kn/list-index-of
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Sep 20, 2022
2 parents e474dae + 6d4622c commit d6d7a81
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dylib",
"ejson",
"errno",
"FALSEPREDICATE",
"ffigen",
"finalizable",
"finalizer",
Expand Down
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
* Performance of indexOf on realm lists has been improved. It now uses realm-core instead of the generic version from ListMixin. ([#911](https://github.com/realm/realm-dart/pull/911)).

### Fixed
* Allow null arguments on query. ([#872](https://github.com/realm/realm-dart/pull/872)). Fixes [#871](https://github.com/realm/realm-dart/issues/871)
* Previously removeAt did not truncate length. ([#884](https://github.com/realm/realm-dart/pull/884)). Fixes [#883](https://github.com/realm/realm-dart/issues/883)
* Allow null arguments on query. ([#871](https://github.com/realm/realm-dart/issues/871))
* Previously removeAt did not truncate length. ([#883](https://github.com/realm/realm-dart/issues/883))
* List.length= now throws, if you try to increase length, ([#894](https://github.com/realm/realm-dart/pull/894)).

* Queries on lists were broken. ([#909](https://github.com/realm/realm-dart/issues/909))
* Queries on results didn't filter the existing results. ([#908](https://github.com/realm/realm-dart/issues/908)).
As an example
```dart
expect(realm.query<Person>('FALSEPREDICATE').query('TRUEPREDICATE'), isEmpty);
```
would fail if any Persons exists
### Compatibility
* Realm Studio: 12.0.0 or later.

### Internal
* Uses Realm Core v12.6.0
* Uses Realm Core v12.7.0

## 0.4.0+beta (2022-08-19)

Expand Down
22 changes: 22 additions & 0 deletions test/list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,28 @@ Future<void> main([List<String>? args]) async {
expect(realm.all<Person>().length, 100);
});

test('List.query when other objects exists', () {
final config = Configuration.local([Team.schema, Person.schema]);
final realm = getRealm(config);

final alice = Person('Alice');
final bob = Person('Bob');
final carol = Person('Carol');
final dan = Person('Dan');
final players = [alice, bob, carol, dan];

final team = Team('Class of 92', players: [alice, bob]);

realm.write(() {
realm.addAll(players);
return realm.add(team);
});

expect(realm.all<Person>(), [alice, bob, carol, dan]);
expect(team.players.query('TRUEPREDICATE'), isNot(realm.all<Person>()));
expect(team.players.query('TRUEPREDICATE'), [alice, bob]);
});

test('ManagedRealmList.indexOf', () {
final config = Configuration.local([Team.schema, Person.schema]);
final realm = getRealm(config);
Expand Down
26 changes: 26 additions & 0 deletions test/results_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,30 @@ Future<void> main([List<String>? args]) async {
final frozenPeopleAgain = freezeResults(people);
expect(identical(frozenPeople, frozenPeopleAgain), false);
});

test('Results.query', () {
final config = Configuration.local([Team.schema, Person.schema]);
final realm = getRealm(config);

final alice = Person('Alice');
final bob = Person('Bob');
final carol = Person('Carol');
final dan = Person('Dan');
final players = [alice, bob, carol, dan];

final team = Team('Class of 92', players: [alice, bob]);

realm.write(() {
realm.addAll(players);
return realm.add(team);
});

expect(realm.all<Person>(), [alice, bob, carol, dan]);
expect(realm.query<Person>('FALSEPREDICATE').query('TRUEPREDICATE'), isEmpty);
expect(realm.query<Person>('FALSEPREDICATE').query('TRUEPREDICATE'), isNot(realm.all<Person>()));
expect(realm.query<Person>("name CONTAINS 'a'"), [carol, dan]); // Alice is capital 'a'
expect(realm.query<Person>("name CONTAINS 'l'"), [alice, carol]);
expect(realm.query<Person>("name CONTAINS 'a'").query("name CONTAINS 'l'"), isNot([alice, carol]));
expect(realm.query<Person>("name CONTAINS 'a'").query("name CONTAINS 'l'"), [carol]);
});
}

0 comments on commit d6d7a81

Please sign in to comment.