Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3744

mJoin Direct Link

$
0
0

I have two tables and I am trying to join them so that I can display in a single cell an array of values which have the same ID from one table which match a single ID from the second table. Basically one table contains property owners and the second table contains properties. A single owner might own multiple properties.

If I use leftJoin it works but my table displays a row for each property instead of combining the joined property data into an array in a single row.

Editor::inst( $db, "owners", "Id" )
    ->fields(
        Field::inst( "owners.Id" )
            ->set( false ),
        Field::inst( "owners.category" )
            ->validator( "Validate::notEmpty" ),
        Field::inst( "owners.create_date" )
            ->set( false )
            ->validator( "Validate::notEmpty" )
            ->getFormatter( function ($val, $data, $field) {
                        $val = date("d/m/Y", strtotime($val));
                        return $val;}), 
        Field::inst( "owners.modified_date" )
            ->set( false )
            ->validator( "Validate::notEmpty" )
            ->getFormatter( function ($val, $data, $field) {
                        $val = date("d/m/Y", strtotime($val));
                        return $val;}),     
        Field::inst( "owners.forename" )
            ->validator( "Validate::notEmpty" ),                            
        Field::inst( "owners.surname" )
            ->validator( "Validate::notEmpty" ),
        Field::inst( "owners.username" )
            ->set( false ),
        Field::inst( "owners.telephone" ),
        Field::inst( "owners.address" ),
        Field::inst( "owners.rules" ),
    Field::inst( "properties.property_name" )
        ->set( false )
    )
    ->where("owners.create_date", $from, ">=")
    ->where("owners.create_date", $to, "<=")
    ->where( "owners.category", $category)
    ->leftJoin( 'properties', 'properties.property_owner', '=', 'owners.Id' )
    ->process( $_POST )
    ->json();  

I think I need to use mJoin with a direct link but I cannot find any examples of how to do this? Is this the right approach or not?

I don't actually wish to edit the property names in the other table directly either, I just want it to display.

Many thanks

Chris


Viewing all articles
Browse latest Browse all 3744

Trending Articles