etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 459 forks source link

Node method setDepth has Error on Laravel 5.1.18 #187

Open palamike opened 8 years ago

palamike commented 8 years ago

I just got this errors.

QueryException in Connection.php line 651: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. (SQL: ROLLBACK TO SAVEPOINT trans2)

My main code has DB::beginTransaction(); seems cause issue with

DB::beginTransaction();
        try{
            $model->title = Input::get('title');
            $model->slug = Input::get('slug');
            $model->description = Input::get('description');
            $model->user_id = Auth::user()->id;

            $model->save();

            DB::commit();
        }//try

in Node.php I commented transaction closure on setDepth method and it works.

public function setDepth() {
    $self = $this;
    //comment the transaction since the main code covered
    //$this->getConnection()->transaction(function() use ($self) {
      $self->reload();

      $level = $self->getLevel();

      $self->newNestedSetQuery()->where($self->getKeyName(), '=', $self->getKey())->update(array($self->getDepthColumnName() => $level));
      $self->setAttribute($self->getDepthColumnName(), $level);
    //});

    return $this;
  }

Please help to check and update the code.

Notes, It happen every where has the code "getConnection()->transaction" so I comments every where.

algorhythm commented 7 years ago

Are your database tables engineered with InnoDB? MyISAM tables are not supporting transactions: http://stackoverflow.com/questions/15678406/when-to-use-myisam-and-innodb