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

Ransack search not working for float fields #1183

Closed
Ezhil-cj opened this issue Dec 3, 2020 · 4 comments
Closed

Ransack search not working for float fields #1183

Ezhil-cj opened this issue Dec 3, 2020 · 4 comments

Comments

@Ezhil-cj
Copy link

Ezhil-cj commented Dec 3, 2020

Ransack Float search

Here i had tried to search float data type, but not found the result as expected and inspected the query generation. Finally found it's not generating for float fields.

searching for float field (paid - float field)

search = 4.2
filter = {}
@purchases = Purchase.all
filter["paid_matches"] = "%#{search}%"
@q = @purchases.ransack(filter)
@purchases = @q.result

Ransack::Search<class: Purchase, base: Grouping <conditions: [Condition <attributes: ["paid"], predicate: cont, values: ["%4.2%"]>], combinator: and>>

will generates sql query like

SELECT purchases.* FROM purchasesWHEREpurchases.deleted = 0 AND (purchases.paid LIKE 0.0) LIMIT 10 OFFSET 0

but expected

SELECT purchases.* FROM purchasesWHEREpurchases.deleted = 0 AND (purchases.paid LIKE %4.2%) LIMIT 10 OFFSET 0

@itsalongstory
Copy link
Contributor

Please use eq instead of matches, as matches is designed for string value.

filter["paid_eq"] = search

@scarroll32
Copy link
Member

Thanks @itsalongstory

Closing this @Ezhil-cj, please re-open if still an issue.

@Ezhil-cj
Copy link
Author

@seanfcarroll, @itsalongstory I'm reopening this because of below reasons,
_eq compare and return string which exactly matches. I need to check _cont with single field on multiple columns. while using _cont it replaces as null for other data types.

Ex:

col 1 (int) col2 (date) col3 (str) col4 (float)

Need to search - 4.2 and test string

While searching above string for a common field with _cont replaces search string NULL or 0 in SQL query generation on other data columns (float, int, date) and returns all data in table.
I need to search over all columns with single field.

@itsalongstory
Copy link
Contributor

@Ezhil-cj Can you provide a executeable test script to describle your case? just like #1163

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

3 participants