In the examples modules I see a simple example of tableSort with one table. Searching online I find a post where they claim Drupal 7 allowed a db_select() object to be created and then extended it with a join(), and then the final ->extend('TableSort');


I need to do an innerJoin() which appears to be a method of the SelectQuery class, and not necessarily a method of the Tablesort class. That's why the docs I see about extenders say it's critical to invoke the TableSort in the instantiation of the db_select object. Thus, my attempt:

$get_all_members = db_select('users', 'u')->innerJoin('members', 'm', 'u.uid = m.uid')->extend('TableSort');

Call to a member function extend() on string

is the response. Is there a way to convert a db_query into a TableSort object like it appears the extender is doing?

Or, could I find a way to combine the fields I need in these two tables to pass to the TableSort object?


The issue is addressed in the thread you referenced. Not all methods for the select class return the new query object. In particular, innerJoin() returns an alias string, not the query object.

Assign your query object so you can reference it outside of the method being called:

$query = db_select('users', 'u')->extend('TableSort')
$query->innerJoin('members', 'm', 'u.uid = m.uid');
//@TODO: add ->fields() ->execute() etc...

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.