This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Vojta Svoboda
Vojta Svoboda

When I use:

Order::where('closed', 0)
            ->where('updated_at',  '<', $this->getOverExpiredTime())
            ->delete();

it will remove all expired Orders (what is right), but it doesn't fire Order::beforeDelete() method, so it's not possible, for example, increase product stock.

If I use this:

$orders = Order::where('closed', 0)
    ->where('updated_at', '<', $this->getOverExpiredTime())
    ->get();

foreach($orders as $order)
{
    $order->delete();
}

it work well. Is it bug or feature?

candrabeqx
candrabeqx

it's normal.

on the first scenario, you are using query builder to delete record directly to database; on the second scenario, records is retrieved and then deleted via the model interface.

AFAIK, this is normal behaviour on most of framework and/or CMS.

for more information, please refer to this page: https://octobercms.com/docs/database/model (go directly to the "Deleting models by query" section).

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.