保存属于CakePHP中多个表的行

时间:2017-08-01 18:08:35

标签: cakephp-3.0 saving-data

我正在尝试在具有复杂关联的系统中保存class SendMessageEvent implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; public $Message; private $UserID; public function __construct($message, $RecepientID) { $this->Message = $message; $this->UserID = $RecepientID; } public function broadcastOn() { return new PrivateChannel('SendMessageChannel.' . $UserID); } }

协会

Order

尝试保存/问题

但是,当我保存时,它只会保存Transactions hasMany TransactionDetails Transactions belongsTo Order TransactionDetails belongsTo Transactions TransactionDetails belongsTo OrderProducts Orders hasMany Transactions Orders hasMany OrderProducts OrderProducts belongsTo Orders OrderProducts hasMany TransactionDetails 中关联的id,而不会保存OrderProducts

为此Transactions保存相关数组:

Orders

这些关联的原因

这是以这种方式设置的,因为在某些区域我们需要将 $associated = [ 'Transactions', 'OrderProducts' => ['associated' => 'TransactionDetails'], 'OrderPackages' => ['associated' => [ 'OrderProducts' => ['associated' => 'TransactionDetails'] ] ]; 拉到一起,而在其他区域我们需要提取特定于该单个产品的'Transactions' => 'TransactionDetails'

问题

是否有办法保存将拥有交易的订单,以及具有必须属于交易的TransactionDetails的OrderProduct。所有这些都是新的保存(在此保存之前不存在任何行)。

'OrderProducts' => 'TransactionDetails'

0 个答案:

没有答案