apache / apache/grails-core

No support to refer to root criteria alias from subquery

Open
#14,623 4 comments 0 reactions 0 assignees View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

What i am trying to achieve is almost similar to what discussed here http://grails.1312388.n4.nabble.com/Subqueries-in-criteria-tp1678501p3078371.html --

Given the domain classes

```
Book {
Author author
Date datePublished
}

Author {
Date dob
}

```
I would like to find all authors who has published book in 2016 (using criteria and exists)

So i would expect some thing like this to work

```
Author.withCriteria {
exists(Book.where({
datePublished = xxx
eqProperty("author.id", "this.id") //here i am trying to access the root criteria alias using this.
}).id())
}
```

However this doesnt give the expected result, and generated sql query looks wrong.

What is expected:
A way to refer to root criteria alias, when doing subqueries

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the criteria query described in the issue, including the nested Book subquery and the eqProperty reference to the root Author criteria. Inspect the criteria and subquery entry points involved in alias resolution and compare the generated SQL with the expected correlation. Done means a subquery can refer to the root criteria alias and returns the expected authors.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.