软删除,关联真实删除的时候,关联表无法真实删除

Open
#555 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
database

Research direction

Start with the autoRelationDelete() entry point shown in the issue and trace how force deletion is propagated from order to its related goods. Check the model delete and soft-delete handling for related records. Done means that force-deleting the order also produces the expected permanent deletion behavior for the related goods and relation data.

Written by the indexing model from the issue text.

Description

$order->together(['goods'])->force(true)->delete();

order 真实删除
goods 软删除

/**
 * 自动关联数据删除(支持一对一及一对多关联)
 * @access protected
 * @return void
 */
protected function autoRelationDelete(): void
{
    foreach ($this->relationWrite as $key => $name) {
        $name   = is_numeric($key) ? $name : $key;
        $result = $this->getRelation($name, true);

        if ($result instanceof Model) {
            $result->delete();
        } elseif ($result instanceof Collection) {
            foreach ($result as $model) {
                $model->delete();
            }
        }
    }
}
Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from top-think/think-orm

All issues in top-think/think-orm

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.