tigrang / cakephp-datatable

JQuery DataTable plugin server-side processing component for CakePHP
47 stars 29 forks source link

Complain on column name from deep association model - Is this do-able? #25

Closed twodeafguysstudio closed 11 years ago

twodeafguysstudio commented 11 years ago

I have this situation where I need to use column/value from a deep association model.

Sample Setup like this -


Model Andrews id name belinda_id

belongsto Belinda


Model Belindas id
name belinda_child_id

belongsto BelindaChild


Model BelindaChilds id name


datatable/index.ctp

foreach ($dtResults as $result) { $this->dtResponse['aaData'][] = array( $result['BelindaChild']['name'] ) }


AndrewsController.php

public $components = array( 'DataTable.DataTable' => array( 'columns' => array( 'BelindaChild.name', ) ) );

public $helpers = array( 'DataTable.DataTable' )

public function index() {

$this->DataTable->setting['Andrew'] = array(
  'contain' => array(

    'Belinda' => array(
      'fields' => array(
        'id',
        'BelindaChild.id'
      ),
    ),

    'BelindaChild' => array(
      'fields' => array(
         'id',
         'name'
      ),
    ),
  ),

  'fields' => array(
    'id',
    'name',
    'Belinda.id'
  ),
),

}

With above codes, an error message would be like this - SQLSTATE[42S22]: Column not found: 1054 Unknown column BelindaChild.name in field list.

Is there another way to do this to use deep association models or someone has solutions for this?

tigrang commented 11 years ago

You'll have to force joins. There are several methods for that you can google.