CakePHP の関連付けに問題があります。
Type に多くの Section を持たせたいので、Section は Type に属します
モデル
class Type extends AppModel {
public $name = 'Type';
public $hasMany = array(
'Section' => array(
'className' => 'Section',
'foreignKey' => 'type_id'
)
);
}
class Section extends AppModel {
public $name = 'Section';
public $belongsTo = array(
'Type' => array(
'className' => 'Type',
'foreignKey' => 'type_id'
)
);
}
コントローラ
class SectionsController extends AppController {
public function lista() {
$this->set('sections', $this->Section->find('all'));
}
}
しかし、結果は次のとおりです。
array(
(int) 0 => array(
'Section' => array(
'id' => '1',
'type_id' => '1',
'name' => 'Advertising',
'visible' => true
)
),