Grestorn opened a new issue, #14422:
URL: https://github.com/apache/grails-core/issues/14422
I have a complex structure which I'll simplify for this example:
```
class Site {
...
}
class Series {
Site primarySite
Set<Site> additionalSites
...
}
class Story {
Series series
...
}
```
I need to select all stories associated with a Site and make further more
detailed selections with that.
First I select all series and that works fine using this:
```
def siteSeriesCriteria() {
return Series.where {
join("additionalSites", JoinType.LEFT)
or {
eq('primarySite', thisSite)
additionalSites {
eq('id', thisSite.id)
}
}
}
}
list = siteSeriesCriteria().id().list()
```
That produces the intended SQL:
```
select
this_.id as y0_
from
series this_
left outer join series_site additional3_ on
this_.id = additional3_.series_additional_sites_id
left outer join site additional1_ on
additional3_.site_id = additional1_.id
where
(this_.primary_site_id =?
or (additional1_.id =?))
```
But when I try to use the deeper nested level that doesn't work anymore:
```
def siteStoryCriteria() {
return Story.where {
series in siteSeriesCriteria().id()
}
}
list = siteStoryCriteria().id().list()
```
Now the join is no longer a left outer:
```
select
this_.id as y0_
from
story this_
where
this_.series_id in (
select
this_.id as y0_
from
series this_
inner join series_site additional3_ on
this_.id = additional3_.series_additional_sites_id
inner join site additional1_ on
additional3_.site_id = additional1_.id
where
(this_.primary_site_id =?
or (additional1_.id =?)))
```
I've read that join() only works on the tree root of the Criteria-tree. But
how am I supposed to solve this?
I've tried to add
join("series.additionalSites", JoinType.LEFT)
to the nested criteria, but that doesn't work either. I'm stumped here...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]