Coder Social home page Coder Social logo

onlyTrashed()->forceDelete() seems to lose the SingleTableInheritance scope, deletes way more than intended about single-table-inheritance HOT 2 OPEN

jonspalmer avatar jonspalmer commented on July 4, 2024
onlyTrashed()->forceDelete() seems to lose the SingleTableInheritance scope, deletes way more than intended

from single-table-inheritance.

Comments (2)

jwadhams avatar jwadhams commented on July 4, 2024

Turned on query logging, this PHP:

\App\Models\AccountIntegrations\TP_TradeEstimate::onlyTrashed()->count();

generates this SQL:

select count(*) as aggregate from `account_integrations` where `account_integrations`.`deleted_at` is not null and `account_integrations`.`type` in (?)	["TP_TradeEstimate"]

but this php:

\App\Models\AccountIntegrations\TP_TradeEstimate::onlyTrashed()->forceDelete();

generates this SQL

delete from `account_integrations` where `account_integrations`.`deleted_at` is not null

... which suggests the problem is somehow specifically with forceDelete not a something obvious like STI scopes being cleared by the onlyTrashed scope.

from single-table-inheritance.

jwadhams avatar jwadhams commented on July 4, 2024

OK, my current hypothesis is that this is a design error in, of all things, MassPrunable.

The implementation and unit tests of \Illuminate\Database\Eloquent\MassPrunable::pruneAll assume that you can force delete all models that meet the prunable criteria, without either prunable or pruneAll bothering to use something like withTrashed.

\Illuminate\Database\Eloquent\Builder::forceDelete, in its commentary, explicitly does NOT apply scopes, but that doesn't seem relevant to its "force" job. What it really needs to ignore is the onDelete behavior (which turns deletes into updates). If I rebuild forceDelete to basically be a clone of delete without onDelete the only tests that fail are related to pruning.

I've got an almost-ready-to-PR branch against Laravel Framework that I'll link here when I submit it. At this rate it looks like no changes to this library will be necessary, but the issue will affect any unpatched versions of Laravel.

from single-table-inheritance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.