orchestral / tenanti

[Package] Multi-tenant Database Schema Manager for Laravel
MIT License
588 stars 52 forks source link

Perform delete on model throws exception #51

Closed basherr closed 7 years ago

basherr commented 7 years ago

When you try to perform delete on any driver Model, It will throw an exception No query results for model [App\Company] 15

Since the code for reset migration at Factory.php is responsible for that as

public function reset($database, $id = null, $pretend = false)
    {
        if (! is_null($id)) {
           //while executeById will look for an id which actually does not exist any more
            return $this->executeById($id, function ($entity) use ($database, $pretend) {
                $this->runReset($entity, $database, $pretend);
            });
        }
        $this->executeByChunk(function ($entities) use ($database, $pretend) {
            foreach ($entities as $entity) {
                $this->runReset($entity, $database, $pretend);
            }
        });
    }

Code at CompanyController

            $company = Company::findOrFail($companyId);
            // $company->manager()->forceDelete();
            $company->delete();
crynobone commented 7 years ago

Could you try replacing the following method on your observer class.

    /**
     * Run on deleted observer.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $entity
     *
     * @return bool
     */
    public function deleting(Model $entity)
    {
        parent::deleted($entity);
    }

    /**
     * Run on deleted observer.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $entity
     *
     * @return bool
     */
    public function deleted(Model $entity)
    {
        //
    }
basherr commented 7 years ago

@crynobone Thanks This just fixed the issue while I forgot to put that. The issue must be resolved on Orchestra Package rather on Observers.

crynobone commented 7 years ago

I can this be resolved on 3.5, but don't think we can introduce a breaking change on 3.4 or below right now.