Skip to content

Commit

Permalink
Fix filter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fummicc1 committed Nov 8, 2024
1 parent 6b8f2e3 commit b19c4d3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Sources/Firestore/FirestoreClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,23 @@ public struct FirestoreEqualFilter: FirestoreQueryFilter {
public struct FirestoreContainFilter: FirestoreQueryFilter {

public var fieldPath: String?
public var value: [Any]
public var value: Any

public init(fieldPath: String?, value: [Any]) {
public init(fieldPath: String?, value: Any) {
self.fieldPath = fieldPath
self.value = value
}

public func build(from: Query) -> Query {
guard let fieldPath = fieldPath, !value.isEmpty else {
guard let fieldPath = fieldPath else {
return from
}
return from.whereField(fieldPath, in: value)
return from.whereField(fieldPath, arrayContains: value)
}

public func build<Model>(type: Model.Type) -> Query where Model: FirestoreModel {
let from = Firestore.firestore().collection(type.collectionName)
guard let fieldPath = fieldPath, !value.isEmpty else {
return from
}
return from.whereField(fieldPath, in: value)
return build(from: from)
}
}

Expand Down

0 comments on commit b19c4d3

Please sign in to comment.