Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-139

Implement Model::createOrFirst() using findOneAndUpdate operation

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • laravel-4.2.0
    • Affects Version/s: laravel-4.1.0
    • Component/s: Laravel
    • None

      nicohell has created Issue #2720: Transaction already in progress in laravel-mongodb

      Issue Text:

      • Laravel-mongodb Version: 4.1
      • PHP Version: 8.2.15
      • Database Driver & Version: db version v6.0.13
      • PHP MongoDB extension version {}1.17.2{}

      Description:

      Using firstOrCreate() in a transaction returns an error

      Steps to reproduce

       

      $mongodb = DB::connection('app');
      $mongodb->beginTransaction();
      // user does not exist and will be created
      \App\Models\User::firstOrCreate(['username' => 'johncarpenter', 'name' => 'carpenter', 'email' => 'john@example.com']);
      $mongodb->rollBack(); 
      

      Expected behaviour

      Manage transaction and commit or rollBack

      Actual behaviour

      retuns error :
      local.ERROR: MongoDB\Driver\Exception\RuntimeException: Transaction already in progress in vendor/mongodb/mongodb/src/Operation/WithTransaction.php:60

      Notes

      create() works fine
      firstOrCreate() and updateOrCreate() do work for updates but do not work for creation as they start a transaction in vendor/mongodb/mongodb/src/Operation/WithTransaction.php

      Hack

      We went through adding a test in vendor/mongodb/mongodb/src/Operation/WithTransaction.php

       

      
      if (!$session->isInTransaction())
      { $session->startTransaction($this->transactionOptions); }
      

       

       

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            tom.selander@mongodb.com Tom Selander
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: