Tables:
language: id (auto increment)
goods: id (auto increment), active
goods_items: goods_id, language_id, name
Data - goods:
id = 1, active = 1
id = 2, active = 1
Data - goods_items:
goods_id = 1, language_id =1, name = test 1
goods_id = 1, language_id =1, name = test 2
goods_id = 1, language_id =1, name = test 3
goods_id = 2, language_id =1, name = test 1
goods_id = 2, language_id =1, name = test 2
goods_id = 2, language_id =1, name = test 3
GoodsTable.php
$this->setTable(‘Goods’);
$this->setDisplayField(‘id’);
$this->setPrimaryKey(‘id’);
$this->hasMany(‘GoodsItems’, [
‘foreignKey’ => ‘goods_id’,
‘dependent’ => true
]);
GoodsItemsTable.php
$this->setTable(‘GoodsItems’);
$this->setDisplayField(‘goods_id’);
$this->setPrimaryKey([‘goods_id’, ‘language_id’]);
$this->belongsTo(‘Goods’, [
‘foreignKey’ => ‘goods_id’,
‘joinType’ => ‘INNER’
]);
Could you please give me an example of how to do so when editing an entry I can edit these items? With patchentity I don’t see goods_id value …
Goods Controller:
$Goods = $this->Goods->get($id, [
‘contain’ => [‘GoodsItems’]
]);
Thank you