Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querydsl Path Depth

I have a entity Document with a list of DocumentValue

@QueryEntity
@Document
public class Document{
 private List<DocumentValue> documentValues;
}

DocumentValue can has also a list of DocumentValue

@QueryEntity
public class DocumentValue {
String value;
String name;
String id;
List<DocumentValue> documentValues;
}

I am now trying to do something like

private QDocumentValue getDocumentValuePathByDepth(int depth){
               ListPath path = QDocument.document.documentValues;
               if (depth != null) {
            for (int i = 0; i < depth; i++) {
                path = path.documentValues.any();
            }
        }
}

Does anybody know if its possible to do an eleMatch in that depth?

Like

ListPath<QDocumentValue> query = getDocumentValuePathByDepth(5);
return query.fieldId.eq(documentFilter.getFieldId()).and(query.value.between(from, to));

One element of documentValues in that depth should fulfill both conditions

BR D.C.

like image 859
DCO Avatar asked May 06 '26 08:05

DCO


1 Answers

elemMatch is supported in Querydsl Mongodb like this

QDocumentValue documentValue = QDocumentValue.documentValue;
query.anyEmbedded(document.documentValues, documentValue)
     .on(documentValue.id.eq(documentFilter.getFieldId(),
         documentValue.value.between(from, to));
like image 72
Timo Westkämper Avatar answered May 08 '26 15:05

Timo Westkämper