Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching model with Soft Delete #23

Open
sembrex opened this issue Mar 7, 2018 · 0 comments
Open

Searching model with Soft Delete #23

sembrex opened this issue Mar 7, 2018 · 0 comments

Comments

@sembrex
Copy link

sembrex commented Mar 7, 2018

I'm using dev-master version of laravel-scout-postgres.
Both withTrashed and onlyTrashed method are not properly handled.
Scout Builder has __soft_deleted in wheres attribute when its config soft_delete set to true. This will throw an Exception because no such column in the table.

Current PostgresEngine only set $query->whereNull($builder->model->getDeletedAtColumn()); if the model use SoftDeletes.

I modify the engine to deal with this problem.

        // Handle soft deletes
        if (!$this->isExternalIndex($builder->model)) {
            if ($this->usesSoftDeletes($builder->model) && isset($builder->wheres['__soft_deleted'])) {
                if ($builder->wheres['__soft_deleted']) {
                    $query->whereNotNull($builder->model->getDeletedAtColumn());
                } else {
                    $query->whereNull($builder->model->getDeletedAtColumn());
                }
                unset($builder->wheres['__soft_deleted']);
            }
        }

        // Apply where clauses that were set on the builder instance if any
        foreach ($builder->wheres as $key => $value) {
            $query->where($key, $value);
            $bindings->push($value);
        }

        /* Deleted
        // If parsed documents are being stored in the model's table
        if (! $this->isExternalIndex($builder->model)) {
            // and the model uses soft deletes we need to exclude trashed rows
            if ($this->usesSoftDeletes($builder->model)) {
                $query->whereNull($builder->model->getDeletedAtColumn());
            }
        }
        */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant