Closed twodeafguysstudio closed 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
foreach ($dtResults as $result) { $this->dtResponse['aaData'][] = array( $result['BelindaChild']['name'] ) }
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?
You'll have to force joins. There are several methods for that you can google.
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() {
}
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?