2016-01-20 15:28
采纳率: 100%
浏览 94

Laravel DB ::事务异常PDO没有活动事务

i have the following code:

$new_models = DB::transaction(function () use ($supplier, $address, $addressDetail) {            
        $new_supplier = $this->setNewSupplier($supplier);
        $new_address = $this->setNewAddress($address);           
        $new_addressDetail = $this->setNewAddressDetail($addressDetail,$new_address->id);           
        return [$new_supplier, $new_address, $new_addressDetail];

The set methods are basically creating the models object with save() at the end; Now this works perfectly fine if 2nd...nth fails BUT NOT if the first one fails. If $this->setNewSupplier($supplier); fails than i get

"PDOException in Connection.php line 541:
There is no active transaction"

Am i doing something wrong here ? Also if i comment $this->rollBack(); from the catch in vendor Connection.php it actually gives me the SQL error. Important part here is that this isn't working only if first save() fails

PS. I am using PostgreSQL not MySQL but i don't think its related

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题