rsql-jpa-specification icon indicating copy to clipboard operation
rsql-jpa-specification copied to clipboard

Add =isEmpty= to QueryDSL support

Open MichaelKoch11 opened this issue 3 years ago • 4 comments

Want to filter Nested Collection (OneToMany) isEmpty or field

Example is

{
{
"id":"252355",
"deleted":false
"properties":[
{"id":"sgdegegwe",
"deleted": false
}
]
}
},{
{
"id":"252555",
"deleted":false
"properties":[
]
}
,{
{
"id":"252555",
"deleted":false
"properties":[
{"id":"sgdegegwe",
"deleted": true
}
]
}
}

rsql Query is then

filter=deleted==false;(properties.deleted==false , properties=isEmpty='')

Response will be

{
{
"id":"252355",
"deleted":false
"properties":[
{"id":"sgdegegwe",
"deleted": false
}
]
}
},{
{
"id":"252555",
"deleted":false
"properties":[
]
}

}

Do i have to implement Custom Operator or how it can easy work?

MichaelKoch11 avatar Sep 28 '22 12:09 MichaelKoch11

Could you provide your expected querydsl query?

perplexhub avatar Nov 17 '22 15:11 perplexhub

Do you mean this line of my request filter=deleted==false;(properties.deleted==false , properties=isEmpty='')

with =isEmpty='' ? Or something else?

MichaelKoch11 avatar Nov 17 '22 15:11 MichaelKoch11

I mean in querydsl syntax.

perplexhub avatar Nov 17 '22 16:11 perplexhub

I reading some pages linked below. After that it should be a left join, where i can check if the join have no result or when is something there with condition. https://stackoverflow.com/questions/51031350/jpa-hibernate-querydsl-left-join-with-condition-doesnt-work https://stackoverflow.com/questions/18190858/querydsl-cross-join-returns-zero-elements https://stackoverflow.com/questions/28568308/filter-with-spring-data-and-querydsl-on-nullable-reference-attribute https://stackoverflow.com/questions/26876740/difficult-with-a-query-and-join

Data Model Element

@OneToMany Element->ElementProperties

After this the query should be

query.from(element)
     .leftJoin(element.properties,elementProperties)
     .fetchJoin()
     .where(elementProperties.deleted.eq(false)).or(elementProperties.id..isNull(()))).fetch();

or some other

query.from(element)
     .leftJoin(element.properties,elementProperties)
     .fetchJoin()
     .where(elementProperties.id.eq("abcde")).or(elementProperties.id..isNull(()))).fetch();


SQL

Select *
from Element el left join ElementProperties eP on eP.element_id = el.id
where eP.deleted == false or eP.element_id IS NULL

With syntax

elementProperties.deleted==false ,elementProperties.id=isnull=''

But I always get only one element. Maybe it helps to define join hints????

MichaelKoch11 avatar Nov 18 '22 12:11 MichaelKoch11