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

planetadeleste
planetadeleste

In some scenery the search doesn't build a correct SQL query. For a model with softDelete and without joins or relations, the final query looks like this:

select
  `table_name`.*
from
  `table_name`
where
  `table_name`.`deleted_at` is null or
  (((lower(table_name.column_one) LIKE '%term%') or
  (lower(table_name.column_two) LIKE '%term%')))

This is because the code at modules/backend/widgets/Lists.php, line 396, say:

        /*
         * Apply a supplied search term for primary columns
         */
        if (count($primarySearchable) > 0) {
            $query->orWhere(function($innerQuery) use ($primarySearchable) {
                $innerQuery->searchWhere($this->searchTerm, $primarySearchable);
            });
        }

If I change the $query->orWhere to $query->where it work fine for this case. But doesn't work on models with relations. At this point, I don't know how to detect if the model has no relations and has softDelete or has relations.

any help? thanks.

P.S. I prefer to ask on forum before open an issue on github. Because I'm not sure if this is really an issue or is there a way to change this from model controller, using listExtendQueryBefore or listExtendQuery methods.

P.S.2 sorry my english

Last updated

daftspunky
daftspunky

You should report this potential bug on the Github issues page.

edit: This was reported already and has been fixed!

Last updated

1-2 of 2

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