FIX joinClass's default_sort is used when nothing else has been set already

This commit is contained in:
Robbie Averill 2018-09-28 15:39:24 +02:00
parent 4aa7fb70ee
commit ac1fe5e9d5

View File

@ -3,6 +3,7 @@
namespace SilverStripe\ORM; namespace SilverStripe\ORM;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\Deprecation;
@ -253,6 +254,13 @@ class ManyManyThroughQueryManipulator implements DataQueryManipulator
); );
} }
// Set a default sort from the join model if available and nothing is already set
if (empty($sqlSelect->getOrderBy())
&& $sort = Config::inst()->get($this->getJoinClass(), 'default_sort')
) {
$sqlSelect->setOrderBy($sort);
}
// Apply join and record sql for later insertion (at end of replacements) // Apply join and record sql for later insertion (at end of replacements)
// By using a string placeholder $$_SUBQUERY_$$ we protect field/table rewrites from interfering twice // By using a string placeholder $$_SUBQUERY_$$ we protect field/table rewrites from interfering twice
// on the already-finalised inner list // on the already-finalised inner list