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',
]);
}