Hi I just made a function to save data in multiple tables. Even Though, I followed the instruction in Instruction for Cakephp 3.0
It saves data in only one table.
Please see what i missed.
Thank you
public function saveTest()
{
$goods = TableRegistry::get('Goods');
//$data = $this->request->data;
$data = [
'brand' => 'brand',
'name' => 'name',
'dis_price' => 100,
'w_price' => 90,
'line_des' => 'haha',
'line_w_des' => 'hehe',
'hash_tag' => 'hoho',
'price' => 100,
'good_stock' => [
'options' => 'asd',
'stock_count' => 100
]];
Debugger::log($data);
$entity = $goods->newEntity($data, [
'associated' => ['GoodsStocks']
]);
Debugger::log($goods->save($entity));
//Debugger::log('3');
}
public function initialize(array $config)
{
$this->entityClass('App\Model\Entity\Goods');
$this->table('goods');
$this->displayField('name');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->hasMany('GoodsStocks',[
'alias' => 'Users',
'foreignKey' => 'good_id',
'dependent' => true
]);
}
Unfortunately It saves the data in only Goods table.
Thank you