0
私は適切な関係を作成したいと思います。だから私がlease
テーブルからデータを取得すると、price
テーブルデータも取得できるようになります。価格表はlease
の複数のIDを持つことができます。cakephpで適切な関連付けを作成する3
テーブルである
リーステーブル
料金表
id
Oの構造価格表のlease_id
に関連する表f lease
私は次のコードで試してみましたが、データを取得できませんでした。あなたが説明
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',
]);
}