cnizzardini / cakephp-datatable

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

Getting error with nested Containable #25

Open AshHimself opened 9 years ago

AshHimself commented 9 years ago

Howdy folks,

I'm getting the following error when I try to filter on a row. I can sort with no issues and data is displaying in datatable no issues but when I search I get the following error in my Ajax response.

  Warning (512): Model "Task" is not associated with model "OR" [CORE/Cake/Model/Behavio   /ContainableBehavior.php, line 342]

My action is as follows;

function getTasks() {
    $this->Task->recursive = 2;

    $this->Task->Behaviors->load('Containable');

    $this->paginate = array(
        'fields' => array('Task.id', 'Task.code', 'Task.job_id'),
        'conditions' => array(
            'Task.scheduled' => 1,
        ),
        'contain' => array(
            'Job' => array(
                'fields' => array(
                    'Job.id',
                ),
                'Site' => array(
                    'fields' => array(
                        'Site.id',
                    )
                )
            )
        )

    );

    $this->DataTable->mDataProp = true;
    $this->set('response', $this->DataTable->getResponse());
    $this->set('_serialize', 'response');
}

Thanks in advanced

AshHimself commented 9 years ago

Just found out in documentation that deep relations in containable is not supported.

cnizzardini commented 9 years ago

I think the dev branch supports it. I have been busy and have not done a release. I'll check this after I get more coffee. Also, have you looked at using the Linkable behavior instead: https://github.com/dereuromark/cakephp-tools/blob/master/Model/Behavior/LinkableBehavior.php

It's much faster then containable, but it only supports one-to-one relations.

fr0z3nfyr commented 7 years ago

Problem is not likely with deep relationship, there is a mistake in the component code. See issue #35 for solution

shawnm0705 commented 7 years ago

I agree with @fr0z3nfyr . After I change the code, everything is fine. Good job!