I have two models one Purchase.php and PurchaseItem.php
(我有两个模型,一个是Purchase.php,另一个是PurchaseItem.php。)
Purchase.php
(Purchase.php)
public function purchase_items()
{
return $this->hasMany('PurchaseItem', 'purchase_id');
}
And PurchaseItem.php
(和PurchaseItem.php)
public function purchase()
{
return $this->belongsTo('Purchase', 'purchase_id');
}
Users can purchase multiple items at a time that he wants.
(用户可以一次购买多个项目。)
During update purchase, users can choose different items. (购买更新时,用户可以选择其他项目。)
In that case, some old items may remove and some new items added. (在这种情况下,某些旧项目可能会删除,而某些新项目可能会添加。)
So what is the best way to update the tables? (那么更新表的最佳方法是什么?)
I can remove all existing items and insert the newly added item during the update purchase. (我可以删除所有现有项目,并在购买更新期间插入新添加的项目。)
But I want to know the best practice in this case. (但是我想知道这种情况下的最佳实践。)
Thanks
(谢谢)
ask by Mahfuz Shishir translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…