0

I am having three tables category, subcategory and subsubcategory. Now category table contain fields as id,name subcategory table contain fields as id, category_id and name and subsubcategory table contain fields as id, subcategory_id and name

now subsubcategory view/index showing columns as name,subcategory_name but i want to display category_name also in my subsubcategory index page

I have used containable behaviour to associate two tables as category and subsubcategory

Here is my code:--

subsubcategoriescontroller:

$contain =array(
'Subcategory'=> array(
    'Category' =>array(
        'fields' => array('id', 'name')
           )
     ));
     $this->Subsubcategory->find('all',array('contain' => $contain));

appmodel:

public $actsAs = array("Containable"); still my subsubcategory page not showing expected results. what will i do?

4

1 回答 1

0

您是否在模型中建立了正确的关系?

class Category extends AppModel {

    public $hasMany = array('Subcategory');
}

class Subcategory extends AppModel {

    public $belongsTo = array('Category');
    public $hasMany = array('Subsubcategory');
}

class Subsubcategory extends AppModel {

    public $belongsTo = array('Subcategory');
}
于 2013-10-22T12:03:09.023 回答