Skip to content

Conversation

@markets
Copy link
Collaborator

@markets markets commented Aug 13, 2018

Re-implement the member_uid searcher by avoiding the column casting thing (gives some problems when sorting the "casted" column as an string). The new strategy: combine both fields in the controller by manupilating the query parameters sent to Ransack.

Closes #398
Closes #400

…hing (gives some problems when sorting the "casted" column as an string). The new strategy: combine both fields in the controller by manupilating the query parameters sent to Ransack.
@markets markets mentioned this pull request Aug 13, 2018
@mllocs
Copy link
Collaborator

mllocs commented Aug 15, 2018

Hello @markets! One question, in the schema.rb it looks like the member_uid column is already an integer, shouldn't Ransack work out of the box like it does with other integer fields?

@markets
Copy link
Collaborator Author

markets commented Aug 15, 2018

Hi @mllocs, I'll try to explain this ... 😅

In current develop if you remove the ransacker (which makes the cast from integer to string), and you try to use the search feature it gives you this error:

PG::UndefinedFunction - ERROR:  operator does not exist: integer ~~* integer
LINE 1: ...."email" ILIKE '%asd%') OR "members"."member_uid" ILIKE 0)  ...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

Seems like postgresql doesn't support ILIKE filters over integer columns. So, in a first try, I implemented a ransacker to make a cast, but then this ransacker is used by Ransack also in the sort_link helper, so now it sorts the list "alphabetically" by a string :(

In summary, this new solution consists of: copy value from original _cont param to a new _eq param (_eq works for integers, since it doesn't use ILIKE under the hood), and combine them with OR before sending this params to Ransack.

Generated SQL:

before

(("users"."username" ILIKE '%10%' OR "users"."email" ILIKE '%10%') 
OR to_char(member_uid, '9999999') ILIKE '%10%') 
ORDER BY to_char(member_uid, '9999999') ASC

this branch

(("users"."username" ILIKE '%10%' OR "users"."email" ILIKE '%10%') 
OR "members"."member_uid" = 10) 
ORDER BY "members"."member_uid" ASC

@mllocs
Copy link
Collaborator

mllocs commented Aug 15, 2018

what about: activerecord-hackery/ransack#765

@markets
Copy link
Collaborator Author

markets commented Aug 15, 2018

@mllocs cool, I'll make a try and send new PR, so we can compare and pick better solution. Thanks!

@markets
Copy link
Collaborator Author

markets commented Aug 15, 2018

@mllocs new proposal in #400

@markets markets deleted the fix_member_uid_search branch October 3, 2018 19:23
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

Successfully merging this pull request may close these issues.

3 participants