Skip to content

Enumerize messes up Arel "LIKE" queries #304

@zor-el

Description

@zor-el

This is quite a nasty issue because of its rather broad impact. It disrupts the operation of other gems that rely on Arel, most notably the Ransack gem where any "contains"-type search on an enumerized field gives the wrong results.

Enumerize version: 2.1.2

Reproduce:

class User < ApplicationRecord
  extend Enumerize
  enumerize :role, in: [:user, :a_admin, :b_admin], predicates: true
end
t = User.arel_table
puts User.where(t[:role].matches '%admin%').to_sql

Outcome:

SELECT "users".* FROM "users" WHERE ("users"."role" LIKE NULL) -- LIKE NULL ?!?

Expected outcome (this is produced w/o the enumerize line):

SELECT "users".* FROM "users" WHERE ("users"."role" LIKE "%admin%")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions