0
我想創建適當的關係b/w兩個表。因此,當我從lease
表中獲取數據時,我也可以獲得price
表數據。價格表可以具有lease
表的多個ID。在cakephp中創建適當的關聯3
表是
表租賃
價格一覽
凡id
鄰的結構f lease
表格與lease_id
價格表相關。
我已經嘗試使用下面的代碼,但無法獲取數據。你描述
class LeasesTable extends Table {
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config) {
parent::initialize($config);
$this->table('leases');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Offices', [
'foreignKey' => 'office_type',
'joinType' => 'INNER'
]);
$this->belongsTo('Countries', [
'foreignKey' => 'country_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Areas', [
'foreignKey' => 'area_id',
'joinType' => 'INNER'
]);
$this->belongsToMany('id', [
'foreignKey' => 'lease_id',
'joinType' => 'INNER',
'joinTable' => 'Prices',
]);
}