1

I'm trying to perform a filter on a group of objects based on a "State" criteria.

...
or {
    office {
        state {
            'in'('abbrev', filters.stateFilter)
        }
    } 
    state {
        'in'('abbrev', filters.stateFilter)
    }
}

If the State filter in the OR is included in the cide it only get objects matching the State and not the Office.State as well. If I remove the State filter code it properly gets the Office.State of the Object.

The criteria needs to get the State for the Object (if it has one) as well as the Office.State of the Object (if it has one).

I'm assuming it has something to do with some implicit joins in the criteria builder?

Any leads would be appreciated!

Vaesive
  • 105
  • 1
  • 11
  • If you set `logSql` to `true` in your `dataSource` config the generated SQL will be logged to the console. That may shed some light on what is going wrong. – Jeff Scott Brown Apr 30 '20 at 22:04
  • Thanks! The logging shows it's performing an inner join which is probably the issue. – Vaesive Apr 30 '20 at 22:32

1 Answers1

0

Thanks to Jeff in the comments I was able to turn on SQL logging to find my issue resolution with some more Googling. As I suspected, it was performing an inner join. Here is the code that I needed to resolve the issue.

...
createAlias('state', 'state', JoinType.LEFT_OUTER_JOIN)
or {
    office {
        'in'('state.abbrev', filters.stateFilter)
    } 
    'in'('state.abbrev', filters.stateFilter)
}
Vaesive
  • 105
  • 1
  • 11