ransack icon indicating copy to clipboard operation
ransack copied to clipboard

polymorphic search type cast issue

Open zephyrpathsofglory opened this issue 6 years ago • 1 comments

Hi, there:

I have a three tables named: audit_logs, users, admin_users, whose corresponding ActiveRecord classes are: AuditLog, User, AdminUser.

Table users's id is integer type, and table admin_users's id is string type, AND BOTH admin_users and users has username field

The table audit_logs has :user_id(string) and :user_type two columns, and AuditLog has a belongs_to relationship: belongs_to :user, polymorphic: true

AND when I use ransack to search: AuditLog.ransack("user_of_User_type_username_eq => 'test')

I got the following error: ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: integer = character varying, it occurred when LEFT OUTER JOIN "users" ON "users"."id" = "audit_log.id".

I don't know if it is a correct behavior to raise error OR it is more reasonable to do a type cast in background in this case.

Thank you!

zephyrpathsofglory avatar Oct 21 '19 10:10 zephyrpathsofglory

@zhangyonguu is it possible to submit a PR with a failing test?

scarroll32 avatar Jan 10 '20 23:01 scarroll32