Does a Laravel rollback transaction support polymorphic relationships?

I have these polymorphic relationships:

staff: 
id - integer
name - string

orders:
id - integer
price - integer

photos:
id - integer
path - string
imageable_id - integer
imageable_type - string

And in the controller:

public function example() {

    \DB::beginTransaction();

    try {

            $staff = Staff::findOrFail(1);

            $row = $staff->photos()->create([ 'path' => 1 ]);

            $row->path = 2;
            $row->save();

            abort(445);

   } catch( \Exception $e ) {

      \DB::rollback()
   }

}

As expected, the current row needs to be removed from the photo table, but it still exists with path = 2

Do I think right away? or is this a misunderstanding?

+4
source share
1 answer

If this is not a transaction rollback, there is one possibility that your table has one MyISAM, since MyISAM tables do not support rollbacks.

So, double-check that the table engine is set correctly on InnoDB.

+1
source

Source: https://habr.com/ru/post/1649000/


All Articles