Skip to content

feat: Add where(arrayContains) support #9167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,59 @@ void main() {
);
});

group('arrayContains', () {
test('supports whereFieldPath', () async {
final collection = await initializeTest(MovieCollectionReference());

await collection.add(
createMovie(title: 'A', genre: ['foo', 'unrelated']),
);
await collection.add(
createMovie(title: 'B', genre: ['bar', 'unrelated']),
);
await collection.add(
createMovie(title: 'C', genre: ['bar', 'unrelated']),
);

final querySnap = await collection
.whereFieldPath(
FieldPath.fromString('genre'),
arrayContains: 'bar',
)
.orderByTitle()
.get();

expect(
querySnap.docs.map((e) => e.data.title),
['B', 'C'],
);
});

test('supports whereProperty', () async {
final collection = await initializeTest(MovieCollectionReference());

await collection.add(
createMovie(title: 'A', genre: ['foo', 'unrelated']),
);
await collection.add(
createMovie(title: 'B', genre: ['bar', 'unrelated']),
);
await collection.add(
createMovie(title: 'C', genre: ['bar', 'unrelated']),
);

final querySnap = await collection
.whereGenre(arrayContains: 'bar')
.orderByTitle()
.get();

expect(
querySnap.docs.map((e) => e.data.title),
['B', 'C'],
);
});
});

test('whereFieldPath', () async {
final collection = await initializeTest(MovieCollectionReference());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Model {
class Nested {
Nested({
required this.value,
required this.simple,
required this.valueList,
required this.boolList,
required this.stringList,
Expand All @@ -29,6 +30,7 @@ class Nested {
Map<String, Object?> toJson() => _$NestedToJson(this);

final Nested? value;
final int? simple;
final List<Nested>? valueList;
final List<bool>? boolList;
final List<String>? stringList;
Expand Down

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

Loading