Skip to content

Commit

Permalink
Fix results query bug (#900)
Browse files Browse the repository at this point in the history
* Add failing test case for Results.query

* Update realm-core to v12.7.0

Includes: e872d35fd Fix `realm_query_parse_for_results` should not ignore result query.(#5841)

* Update bindings

* Update CHANGELOG
  • Loading branch information
nielsenko authored Sep 20, 2022
1 parent dfb4780 commit 6d4622c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* 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.

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 6d4622c

Please sign in to comment.