@@ -257,28 +257,39 @@ def __getattr__(self, name: str) -> Self:
257257 def __str__ (self ) -> str :
258258 return self ._to_string (self )
259259
260- def any (self ) -> Self :
260+ def any (self , collection_name : str ) -> Self :
261261 """Any nested objects have to match the filter condition.
262262
263+ Args:
264+ collection_name: The name of the collection to which apply the `any` operator.
265+
263266 Returns:
264267 RQLQuery: RQLQuery with new condition
265268
266269 Examples:
267- RQLQuery(saleDetails__orderQty__gt=11).any()
268- will result: any(saleDetails,orderQty=11)
270+ RQLQuery(orderQty__gt=11).any("saleDetails")
271+ will result (single): any(saleDetails,orderQty=11)
272+ (RQLQuery(orderQty__gt=11) & RQLQuery(price__lt=100)).any("saleDetails")
273+ will result (multiple): any(and(saleDetails,gt(orderQty,11),lt(price,100)))
269274 """
270- return self .new ( op = self .OP_ANY , children = [ self ] )
275+ return self ._nest ( self .OP_ANY , collection_name )
271276
272- def all (self ) -> Self :
277+ def all (self , collection_name : str ) -> Self :
273278 """All nested objects have to match the filter condition.
274279
280+ Args:
281+ collection_name: The name of the collection to which apply the `all` operator.
282+
275283 Returns:
276284 RQLQuery: RQLQuery with new condition
277285
278- Example:
279- RQLQuery(saleDetails__orderQty__gt=1).all()
286+ Examples:
287+ RQLQuery(orderQty__gt=1).all("saleDetails")
288+ will result (single): all(saleDetails,gt(orderQty,1))
289+ (RQLQuery(orderQty__gt=11) & RQLQuery(price__lt=100)).all("saleDetails")
290+ will result (multiple): all(and(saleDetails,gt(orderQty,11),lt(price,100)))
280291 """
281- return self .new ( op = self .OP_ALL , children = [ self ] )
292+ return self ._nest ( self .OP_ALL , collection_name )
282293
283294 def n (self , name : str ) -> Self : # noqa: WPS111
284295 """Set the current field for this `RQLQuery` object.
@@ -522,3 +533,9 @@ def _append(self, query: "RQLQuery") -> "RQLQuery" | Self:
522533
523534 self .children .append (query )
524535 return self
536+
537+ def _nest (self , op : str , collection_name : str ) -> Self :
538+ name = collection_name .replace ("__" , "." )
539+ collection = self ._to_string (self ) if self .children else self .expr or ""
540+ expr = f"{ op } ({ name } ,{ collection } )"
541+ return self .new (expr = expr )
0 commit comments