diff --git a/packages/rs-drive/src/query/conditions.rs b/packages/rs-drive/src/query/conditions.rs index 24b5600f9f..2f565968db 100644 --- a/packages/rs-drive/src/query/conditions.rs +++ b/packages/rs-drive/src/query/conditions.rs @@ -1048,7 +1048,6 @@ impl<'a> WhereClause { Ok(query) } - /// Build where clauses from operations pub(crate) fn build_where_clauses_from_operations( binary_operation: &ast::Expr, document_type: &DocumentType, @@ -1078,13 +1077,16 @@ impl<'a> WhereClause { "$id" | "$ownerId" => Cow::Owned(DocumentPropertyType::Identifier), "$createdAt" | "$updatedAt" => Cow::Owned(DocumentPropertyType::Date), "$revision" => Cow::Owned(DocumentPropertyType::U64), - property_name => { - let Some(property) = document_type.properties().get(property_name) else { - return Err(Error::Query(QuerySyntaxError::InvalidInClause( - "Invalid query: in clause property not in document type" - .to_string(), - ))); - }; + _ => { + let property = document_type + .flattened_properties() + .get(&field_name) + .ok_or_else(|| { + Error::Query(QuerySyntaxError::InvalidSQL(format!( + "Invalid query: property named {} not in document type", + field_name + ))) + })?; Cow::Borrowed(&property.property_type) } }; @@ -1213,14 +1215,16 @@ impl<'a> WhereClause { "$id" | "$ownerId" => Cow::Owned(DocumentPropertyType::Identifier), "$createdAt" | "$updatedAt" => Cow::Owned(DocumentPropertyType::Date), "$revision" => Cow::Owned(DocumentPropertyType::U64), - property_name => { - let Some(property) = document_type.properties().get(property_name) - else { - return Err(Error::Query(QuerySyntaxError::InvalidSQL(format!( - "Invalid query: property named {} not in document type", - field_name.as_str() - )))); - }; + _ => { + let property = document_type + .flattened_properties() + .get(&field_name) + .ok_or_else(|| { + Error::Query(QuerySyntaxError::InvalidSQL(format!( + "Invalid query: property named {} not in document type", + field_name + ))) + })?; Cow::Borrowed(&property.property_type) } };