$this->sort =
[];
} // Gather the SQL field aliases first to make sure every field table
// necessary is added. This might change whether the query is simple or
// not. See below for more on simple queries.
$sort =
[];
if ($this->sort
) { foreach ($this->sort
as $key =>
$data) { $sort[$key] =
$this->
getSqlField($data['field'
],
$data['langcode'
]);
} } $simple_query =
$this->
isSimpleQuery();
// If the query is set up for paging either via pager or by range or a
// count is requested, then the correct amount of rows returned is
// important. If the entity has a data table or multiple value fields are
// involved then each revision might appear in several rows and this needs
// a significantly more complex query.
if (!
$simple_query) { // First, GROUP BY revision id (if it has been added) and entity id.
// Now each group contains a single revision of an entity.
foreach ($this->sqlFields
as $field) { $group_by = "
$field[0
].
$field[1
]";
$this->sqlGroupBy
[$group_by] =
$group_by;
}