cnizzardini / cakephp-datatable

CakePHP Component for interoperability between CakePHP 2.x and jQuery DataTables plugin.
62 stars 47 forks source link

Internal server error after upgrade #11

Closed ClaudeMa closed 10 years ago

ClaudeMa commented 10 years ago

Controller work fine with version 1.1.0 Upgrading to 1.1.1 give internal server error 500 with

"error":{"errorInfo":["42S22",1054,"Unknown column 'Nature.nature' in 'field list'"],"queryString":"SELECT Ticket.id, Ticket.created, Ticket.titre, Nature.nature, Statut.statut, Concerne.nom, Urgence.urgence, Ticket.modified, User.username, Statut.couleur FROM efpad.tickets AS Ticket WHERE 1 = 1 ORDER BY Concerne.nom ASC LIMIT 0"}} returning to previous version solve error

my controler code:

public function index() {

    $this->layout = 'annuaire';     
    if($this->RequestHandler->responseType() == 'json') {
            $this->paginate = array(
                'fields' => array('Ticket.id','Ticket.created','Ticket.titre', 'Nature.nature', 'Statut.statut', 'Concerne.nom','Urgence.urgence','Ticket.modified', 'User.username', 'Statut.couleur'),
            );
        $this->DataTable->emptyElements = 1;
        $this->set('tickets', $this->DataTable->getResponse());
        $this->set('_serialize','tickets');
        }
}

my model code

<?php // app/Model/Ticket.php class Ticket extends AppModel { public $name = 'Ticket'; public $actsAs = array('Linkable','Containable'); public $displayField = 'ticket'; public $belongsTo = array( 'Groupe' => array( 'className' => 'Groupe', 'foreignKey'=> 'groupe_id' ), 'User' => array( 'className' => 'User', 'foreignKey'=> 'user_id' ), 'Concerne' => array( 'className' => 'Concerne', 'foreignKey'=> 'concerne_id' ), 'Nature' => array( 'className' => 'Nature', 'foreignKey'=> 'nature_id' ), 'Urgence' => array( 'className' => 'Urgence', 'foreignKey'=> 'urgence_id' ), 'Statut' => array( 'className' => 'Statut', 'foreignKey'=> 'statut_id' ), );

public $validate = array(
        'titre' => array(
            'notempty' => array(
                'rule' => array('notempty'),                
                )
        ),
        /*'ticket'=>array(
            'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'Saisissez le texte du ticket',
            'allowEmpty' => false,
            'required' => true,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            )
        )*/
        );

public $order = 'Concerne.nom';

Cakephp 2.4.1 PHP Version 5.4.4-14+deb7u5 Apache2 Api version 20051115 Debian Wheezy x86_64

cnizzardini commented 10 years ago

Are you using the absolute most recent. Someone reported a bug with CakePHP 2.4.1 and pushed a fix about a week or so ago. It has to do with how cake handles limits in MySQL. Let me know. Thanks.

cnizzardini commented 10 years ago

Also I notice in your paginate configuration you are referencing multiple tables in the 'fields' list:

Nature,Statut,Concerne,Urgence,Ticket,User

You need to tell paginate you are joining on these tables with something like this mock code:

if($this->RequestHandler->responseType() == 'json') {
    $this->paginate = array(
        'fields' => array('Ticket.id','Ticket.created','Ticket.titre'),
        'link' => array(
            'Nature' => array(
                'fields' => array(
                    'nature'
                )
            ),
            'Statut' => array(
                'fields' => array(
                    'statut'
                )
            )
        )
    );
    $this->DataTable->fields = array('Ticket.id','Ticket.created','Ticket.titre', 'Nature.nature', 'Statut.statut', 'Concerne.nom','Urgence.urgence','Ticket.modified', 'User.username', 'Statut.couleur');
    $this->DataTable->emptyElements = 1;
    $this->set('tickets', $this->DataTable->getResponse());
    $this->set('_serialize','tickets');
}
cnizzardini commented 10 years ago

Also I've had problems using the emptyElements property, please read previous closed issues as they often answer your questions....

cnizzardini commented 10 years ago

Closed due to lack of response