0

So I have 2 Models

Performer Model:

class Performer extends AppModel {
    public $actsAs = array('Containable');
    var $name = 'Performer';
    var $hasAndBelongsToMany = array('Genre');
}

Genre Model:

class Genre extends AppModel {
    var $actsAs = array('Tree');
    var $hasAndBelongsToMany = array('Performer');
}

Controller Action:

public function admin_index(){

     $this->paginate = array(
                    'limit' => 24,
                    'contain' => array(
                    'Genre')); 

     $performers = $this->paginate();              

     $this->set('performers',$performers);
     $this->autoRender = true;
     $this->layout = 'default';
}

View :

<table>
 <tr>
 <th><?= $this->Paginator->sort('id', 'ID') ?></th>
 <th><?= $this->Paginator->sort('name', 'Name') ?></th>
    <th><?= $this->Paginator->sort('Genre.name', 'Genre') ?></th>
 </tr>
   <?php foreach ($performers as $performer): ?>
 <tr>
    <td><?= $performer['Performer']['id'] ?> </td>
    <td><?= h($performer['Performer']['name']) ?> </td>
    <td><?= $performer['Genre'][0]['name'] ?> </td>
</tr>
<?php endforeach; ?>
</table>

Question: When I use $this->Paginator->sort('Genre.name', 'Genre'); I receive a: Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Genre.name' in 'order clause'

What can I do to sort by Genre.name using HABTM?

Nick
  • 59
  • 2
  • 9

0 Answers0