0

I have a custom module where i want to show a table on a page. The rows of this table are the representation of a list of objects stored in database table A.

Most of the columns show data from fields in database table A. But two fields are taken from database table B. This table contains a variable count of objects linked with the objects in database table A. For the said two columns the table takes two defined parameters of the first linked object from databse table B for each row/object from database table A.

So far so good. Now i want to enable TableSort for the table and created this function, i used leftjoin since i want to show all elements from table A and complement this with the two parameters from table B:

public static function findAllUseTableSortAndUsePagerDefault($header, $limit) {

$query = db_select('table_a', 'a');
$query->leftJoin('table_b', 'b', 'a.id = b.linked_id');


$results = $query
  ->extend('TableSort')
  ->fields('a', self::$databaseFields)
  ->fields('b', ['linked_id','param1', 'param2'])
  ->extend('PagerDefault')
  ->limit($limit)
  ->orderByHeader($header)
  ->orderBy('id')
  ->execute()
;
return self::databaseResultsToObjects($results);

}

It seems to works for all fields from database table a and at a first glance it seemed to work for the fields of database table b too, but here and there the sorting is wrong, e.g. (since its sorting alphabetically) it lists param1 values starting with 'A' then with 'B' and then some with 'A' again and then continuing normally.

I can't put my finger on it why.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.