0
私はいくつかの関連テーブルを持っており、メインのため、これはモデルです:関係テーブルの関連情報をすべて取得するにはどうすればよいですか?
<?php
App::uses('AppModel', 'Model');
class Information extends AppModel {
public $useTable = 'informations';
public $displayField = 'name';
public $validate = array(
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'The field name can not be empty',
),
),
'lastname' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'The field lastname can not be empty',
),
),
'email' => array(
'email' => array(
'rule' => array('email'),
'message' => 'The email address is not correct',
),
),
);
public $belongsTo = array(
'Country' => array(
'className' => 'Country',
'foreignKey' => 'countries_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $hasMany = array(
'Education' => array(
'className' => 'Education',
'foreignKey' => 'informations_id',
'dependent' => true
),
'Experience' => array(
'className' => 'Experience',
'foreignKey' => 'informations_id',
'dependent' => true
),
'Attachment' => array(
'className' => 'Attachment',
'foreignKey' => 'informations_id',
'dependent' => true
)
);
}
私はIDに関連するすべてのデータを取得する必要がありますが、私はこのコードを使用してデータを取得しようとすると、 :
public function view($id = null) {
$this->Information->id = $id;
if (!$this->Information->exists()) {
throw new NotFoundException(__('Invalid information'));
}
$this->set('information', $this->Information->read(null, $id));
}
教育、経験と添付ファイルのみこの情報を示していないテーブルから情報を取得することです:
Array
(
[id] => 9
[name] => Reynier
[lastname] => Perez Mira
[email] => [email protected]
[mobile_phone] => 04241805609
[home_phone] => 02735555899
[address] => asdas
[picture] => skills.png
[other_information] => asdasdasd
[recruitment_status] => Call for Interview
[countries_id] => 9
)
なぜですか?私は何かが欠けている?
$ this-> Information-> recursive = 1を設定してみてください。読み取り前の行に表示されます。また、CakePHPの本の "Containable"動作を調べることもできます。 – Dave