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

Can't Filters Numeric Values And Boolean Values #68

Open
AhnabShahin opened this issue Jun 3, 2024 · 5 comments
Open

Can't Filters Numeric Values And Boolean Values #68

AhnabShahin opened this issue Jun 3, 2024 · 5 comments

Comments

@AhnabShahin
Copy link

AhnabShahin commented Jun 3, 2024

Filter example :

  • ?filters[gpa][$eq]=3.11
  • ?filters[gpa][$eq]=4
  • ?filters[gpa][$eq]=False
  • ?filters[is_default][$eq]=true

Database Using : MongoDB using https://github.com/mongodb/laravel-mongodb

Problem Details:

The URL parameters are being converted into strings, but the corresponding values in my database are integers or floats. As a result, there's a mismatch and I'm not getting any matching results.

image

@AhnabShahin AhnabShahin changed the title Can't Filters Numeric Value Can't Filters Numeric Values And Boolean Values Jun 3, 2024
@AhnabShahin
Copy link
Author

Thank you to the author and contributors for creating this useful package! Purity has significantly enhanced my workflow, and I deeply appreciate the effort and dedication that has gone into its development.

However, I have encountered an issue where I can't filter numeric values and Boolean values.
Here is the solution in a pull request that will convert the value into a numeric if it is numeric, or a Boolean if it is Boolean

PR For Issues 68

@abbasudo
Copy link
Owner

abbasudo commented Jun 3, 2024

Hi @AhnabShahin .
It's good to hear that Purity helped you in your projects. Also, Thank you for your contribution to Purity.
In Purity, values get converted to a string and won't cause any errors because Purity in its core uses Laravels query builder, for example, the $eq uses the where() function from eloquent. This function accepts string values and converts them into corresponding values. in the case of boolean values, you must filter them by 0 and 1.
Furthermore, in #70 I added more tests for different value types to confirm the correctness of Laravel Purity. Check out this tests

@abbasudo
Copy link
Owner

abbasudo commented Jun 3, 2024

@AhnabShahin keep in mind all of our tests are running in SQLite and MySQL databases and Eloquent if you have any errors it is related to MongoDB and Moloquent. Do have mismatched results?

@AhnabShahin
Copy link
Author

@abbasudo It's not an error! I'm just getting mismatched results when using MongoDB with the help of the "laravel-mongodb" package, which is the official MongoDB package for Laravel. If this "Purity" package doesn't support MongoDB, I'm willing to fork it to make it workable and suitable for myself.

@abbasudo
Copy link
Owner

@AhnabShahin that's great. Please inform me of any updates on your fork.

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

2 participants