cnizzardini / cakephp-datatable

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

Configuring Controller paginator() throws SQL error #5

Closed optimumenergy closed 10 years ago

optimumenergy commented 10 years ago

Well, I was about to build it and here you have done it all for me :) Thank you!

One issue - as long as I do NOT set the 'fields' and 'conditions' keys in the controller's paginator(), the component works just fine. But if I add anything into these keys, like this:

$this->paginate(array( 'fields' => 'Customer.modified', 'conditions' => array( 'active'=>1 ) ));

Cake throws a SQL error, complaining about this WHERE statement that gets generated: WHERE fields = 'Customer.modified' AND conditions = (1)

I'm really not clear on what's going on in the component to make this happen but could it be linked to statements like line 69:

$conditions = isset($this->controller->paginate['conditions']) ? $this->controller->paginate['conditions'] : null;

?

Any help is getting this right would be appreciated. I'm sure it s on my end, but I can't see what I'm missing.

Thanks.

cnizzardini commented 10 years ago

Not sure if this is shorthand or real life code, but Fields should be an array:

        'fields' => array(
            'Customer.modified'
        ),

What version of CakePHP are you running? Also have you looked at some of the examples in the test application: https://github.com/cnizzdotcom/cakephp-datatable/blob/master/test/app/Controller/CitiesController.php which you can see running live here: http://cakephpdatatables.cnizz.com/

optimumenergy commented 10 years ago

I'm SUCH an idiot. No, it wasn't shorthand, it was long hours, not enough sleep (or coffee)

Thank you :+1:

It's a great Component. I think I'll have to extend it by adding links to models (eg users name -> users/view/id) the usual edit/view/delete buttons I think. I need these in my grid. Haven't thought about the best way to do that. I also haven't looked in the examples yet, maybe you've do it already ...

Thanks again

cnizzardini commented 10 years ago

Lack of coffee followed by a syntax error does not signify stupidity. Thanks!