Need to count records in an MJoin

Need to count records in an MJoin

delnazdelnaz Posts: 2Questions: 1Answers: 0

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

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    Answer ✓

    Does it need to be editable? If not, use a COUNT() expression in a Field::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

  • delnazdelnaz Posts: 2Questions: 1Answers: 0

    Thanks, The solution is working for me.

Sign In or Register to comment.