@@ -257,28 +257,33 @@ 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
263263 Returns:
264264 RQLQuery: RQLQuery with new condition
265265
266266 Examples:
267- RQLQuery(saleDetails__orderQty__gt=11).any()
268- will result: any(saleDetails,orderQty=11)
267+ RQLQuery(orderQty__gt=11).any("saleDetails")
268+ will result (single): any(saleDetails,orderQty=11)
269+ (RQLQuery(orderQty__gt=11) & RQLQuery(price__lt=100)).any("saleDetails")
270+ will result (multiple): any(and(saleDetails,gt(orderQty,11),lt(price,100)))
269271 """
270- return self .new ( op = self .OP_ANY , children = [ self ] )
272+ return self ._nest ( self .OP_ANY , collection_name )
271273
272- def all (self ) -> Self :
274+ def all (self , collection_name : str ) -> Self :
273275 """All nested objects have to match the filter condition.
274276
275277 Returns:
276278 RQLQuery: RQLQuery with new condition
277279
278- Example:
279- RQLQuery(saleDetails__orderQty__gt=1).all()
280+ Examples:
281+ RQLQuery(orderQty__gt=1).all("saleDetails")
282+ will result (single): all(saleDetails,gt(orderQty,1))
283+ (RQLQuery(orderQty__gt=11) & RQLQuery(price__lt=100)).all("saleDetails")
284+ will result (multiple): all(and(saleDetails,gt(orderQty,11),lt(price,100)))
280285 """
281- return self .new ( op = self .OP_ALL , children = [ self ] )
286+ return self ._nest ( self .OP_ALL , collection_name )
282287
283288 def n (self , name : str ) -> Self : # noqa: WPS111
284289 """Set the current field for this `RQLQuery` object.
@@ -522,3 +527,12 @@ def _append(self, query: "RQLQuery") -> "RQLQuery" | Self:
522527
523528 self .children .append (query )
524529 return self
530+
531+ def _nest (self , op : str , collection_name : str ) -> Self :
532+ name = collection_name .replace ("__" , "." )
533+
534+ collection = self ._to_string (self ) if self .children else self .expr or ""
535+
536+ expr = f"{ op } ({ name } ,{ collection } )"
537+
538+ return self .new (expr = expr )
0 commit comments