silverstripe/silverstripe-framework — pull request #3019 by tractorcow (2014-04-08 20:53:10+00:00)
Title: BUG Fix data query not always joining necessary tables

Fixes #2846

Previously, `DataQuery::getFinalisedQuery` would try to optimistically reduce the number of joined tables for certain queries. Sometimes it would be a bit over-ethusiastic, and omit tables that the query relied on later for sorting.

Since there's currently no robust way to accurately anticipate which tables can and can't be joined, it joins all tables vertically in the requested hierarchy (from `$baseClass` up until the queried class). If a table hierarchy is shallow (as it should be in practice) this will only be a slight performance hit, and only in cases where lots of limited-column queries would be done.