tigrang / cakephp-datatable

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

Belongs to.. #33

Closed joshdcid closed 11 years ago

joshdcid commented 11 years ago

Hi @tigrang .. thanks for the plugin.. how can i use the belongs to relationship in the controller..? I have two models: Collects: public $belongsTo = array( 'Laborer' => array( 'className' => 'Laborer', 'foreignKey' => 'laborer_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); Laborer: public $hasMany = array( 'Collect' => array( 'className' => 'Collect', 'foreignKey' => 'laborer_id', 'dependent' => false, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => '' ) ); and in my Collects Controller inside index function: $this->DataTable->paginate = array('Collect');

And i want to display the laborer name.. not just the laborer_id... can i do that?

Thanks in advance.

tigrang commented 11 years ago

All you need to do is make sure a join is being made instead of a separate query. If it's not already, search for ad-hoc joins in cakephp.

When you're setting up fields in the settings for this plugin, have Laborer.name

joshdcid commented 11 years ago

i just change the settings to Laborer.name and it work! Thanks...

tigrang commented 11 years ago

Awesome. No problem :)