Active Query Builder support area

Issue with QueryTransformer and Distinct keyword

Avatar
  • updated
  • Fixed

I have run into an issue when passing a query that uses the distinct modifier and then adding a filter to an aliased column. The relevant part of the code needed to replicate would look like this:

When the QueryTransformer adds the filter to a query with distinct it is wrapping with a subquery but then it does not use the alias for the filter which gives a query that will not execute. So for my example above you would get something like this:

Select * From (Select Distinct my_table.id Identifier From my_table) q Where q.id = 1

where q.id is invalid for the filter, it should use the alias q.Identifier

Note: If I set QueryTransformer property AlwaysWrapInSubQuery prior to applying the filter, the result sql is correct and utilizes my alias. I would prefer to not have this property set though. 

Hope my post is clear, Thanks!

Luke