Skip to content
  • Prem Sichanugrist's avatar
    0b157f8d
    Fix `define_attribute_method` with Symbol in AR · 0b157f8d
    Prem Sichanugrist authored
    This issue is only appear when you try to call `define_attribute_method`
    and passing a symbol in Active Record. It does not appear in isolation
    in Active Model itself.
    
    Before this patch, when you run `User.define_attribute_method :foo`, you
    will get:
    
        NoMethodError: undefined method `unpack' for :foo:Symbol
            from activerecord/lib/active_record/attribute_methods/read.rb:28:in `define_method_attribute'
            from activerecord/lib/active_record/attribute_methods/primary_key.rb:61:in `define_method_attribute'
            from activemodel/lib/active_model/attribute_methods.rb:292:in `block in define_attribute_method'
            from activemodel/lib/active_model/attribute_methods.rb:285:in `each'
            from activemodel/lib/active_model/attribute_methods.rb:285:in `define_attribute_method'
    
    This patch contains both a fix in Active Model and a test in Active
    Record for this error.
    0b157f8d
    Fix `define_attribute_method` with Symbol in AR
    Prem Sichanugrist authored
    This issue is only appear when you try to call `define_attribute_method`
    and passing a symbol in Active Record. It does not appear in isolation
    in Active Model itself.
    
    Before this patch, when you run `User.define_attribute_method :foo`, you
    will get:
    
        NoMethodError: undefined method `unpack' for :foo:Symbol
            from activerecord/lib/active_record/attribute_methods/read.rb:28:in `define_method_attribute'
            from activerecord/lib/active_record/attribute_methods/primary_key.rb:61:in `define_method_attribute'
            from activemodel/lib/active_model/attribute_methods.rb:292:in `block in define_attribute_method'
            from activemodel/lib/active_model/attribute_methods.rb:285:in `each'
            from activemodel/lib/active_model/attribute_methods.rb:285:in `define_attribute_method'
    
    This patch contains both a fix in Active Model and a test in Active
    Record for this error.
Loading