Need to count records in an MJoin
Need to count records in an MJoin
I have this Join that links two tables
$editor = Editor::inst( $db, 'table1' )
->fields(
Field::inst( 'table1.id' ),
)
->join(
Mjoin::inst( 'table2' )
->link( 'table1.id', 'table2.person' )
->fields(
Field::inst( 'id' )
)
)
The join returns an array of table2 records for each table1 record which is correct.
What I need is to return the count of this array and not the records. Is this possible?
I know that in the datatable I could use a renderer and display array.length but this means that my column would not be sortable.
This question has an accepted answers - jump to answer
Answers
Does it need to be editable? If not, use a
COUNT()
expression in aField::inst(...)
to create a sub-query.If you do need it to be editable, and you are using server-side processing (which it sounds like you might be?) then I'm afraid there is no way to do sorting with Mjoins at the moment.
Allan
Thanks, The solution is working for me.