Skip to content

scope with enum symbol causing undefined method []' for nil:NilClass` #54

@denmarkmeralpis

Description

@denmarkmeralpis
# foo.rb
class Foo < ApplicationRecord
  enum day: [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]

  validates :start_time, :end_time, overlap: {
    scope: [:day, :another_column]
  }
end

Here's what I got when validation fails:

undefined method `[]' for nil:NilClass
Extracted source (around line #184):

#182 
#183       if is_enum_attribute?(record, attr_name)
*184         value = record.class.defined_enums[attr_name][value]
#185       end
#186 
#187       value
...

I think you need to cast the attr_name to string something like this attr_name.to_s

value = record.class.defined_enums[attr_name][value]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions