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

Fix backend search #775

Closed
wants to merge 1 commit into from
Closed

Conversation

alvaro-canepa
Copy link
Contributor

Backend search doesn't work properly if exists a previous where sentence of deleted_at.
The problem is on the use of orWhere, without validate for previous wheres, making a final SQL like this

`table_name`.`deleted_at` is null or (((lower(table_name.column_one) LIKE '%term%')

I don't know if my solution is the correct one. It work fine on my tests.

Thanks

Backend search doesn't work properly if exists a previous where sentence of `deleted_at`.
The problem is on the use of `orWhere`, without validate for previous wheres, making a final SQL like this
    `table_name`.`deleted_at` is null or (((lower(table_name.column_one) LIKE '%term%')

I don't know if my solution is the correct one.

Thanks
@daftspunk
Copy link
Member

Can you please add more detail?

  • Bug summary: Make sure your summary reflects what the problem is and where it is.
  • Request location: Enter the URL where this bug occurs, if applicable.
  • Reproduce steps: Clearly mention the steps to reproduce the bug.
  • Expected result: How OctoberCMS should behave on above mentioned steps.
  • Actual result: What is the actual result on running above steps i.e. the bug behavior - include any error messages.

@alvaro-canepa
Copy link
Contributor Author

Summary

Having a Model with SoftDelete and without any relation the final query look 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%')))

In this case, the method for the $query need to be where() instead of orWhere().
But, if there are relations on the query, the use of orWhere() is the correct one.

In my fixed code, I try to read the last where sentence and find the "deleted_at" column name, if exists, use "and" in $bool variable of where method. I don't know if there are some constant or method to get the softDelete column name (deleted_at as default).

Request location

modules/backend/widgets/Lists.php at line 409

Expected result

When the model has softdelete, and the list are separated by active elements and deleted elements (trash). The search must be return the items, corresponding the term of search and the model columns.

Actual result

Using the list search, in the backend, if the model has softdelete, the search returns all the items.

Sorry my English. I try to be clear on the explication.

@tresbach
Copy link
Contributor

Hi, any update on this? List search really doesn't work along with SoftDeletingTrait/SoftDeletes..

@daftspunk
Copy link
Member

This is a dirty fix for a problem I cannot see demonstrated. I have created a list using a model with soft deletes, the list can be searched successfully.

@daftspunk daftspunk closed this Feb 21, 2015
daftspunk added a commit that referenced this pull request Mar 25, 2015
@daftspunk
Copy link
Member

I was later able to replicate this, it has now been fixed in 8d93c9f

@alvaro-canepa
Copy link
Contributor Author

I try this change before, and fail on common queries (without softDelete). I know my solution was dirty, but this simple solution not work on all possible environments.
Sorry my English and thanks for this amazing CMS!

@daftspunk
Copy link
Member

Can you provide an example of a common query where it fails?

@alvaro-canepa
Copy link
Contributor Author

Let me make some tests on the Beta version. I still using the Laravel 4.2 version.

@daftspunk
Copy link
Member

Ok, that's fine, please submit as a new Issue if you discover any problems.

@daftspunk
Copy link
Member

I noticed there was a problem here when searching related columns, I managed to resolve it in 93dd61e

@alvaro-canepa
Copy link
Contributor Author

Great, I will testing soon, actually have no time :(
Thanks daftspunk!!!

daftspunk added a commit to octoberrain/backend that referenced this pull request Apr 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants