Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5018

`send(:format)` on relation's model instance call Kernel#format and not field's read method after parent is reloaded

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 7.0.0
    • Component/s: Associations
    • Environment:
      Dev env : ArchLinux
      Prod env : Ubuntu 18.04.3

      Hello,

      When acessing the field `format` via `send` or `_send_` on an instance from a relation, then it seems to call `Kernel#format` (causing an ArgumentError) and not the field `format` read method.

      It doesn't happen if the instance if from a `find` or `where`, only if gotten via a relation.

      Here come an quick example :

      class Test1
        include Mongoid::Document  has_one :test2, class_name: "Test2"
      end
      
      class Test2
        include Mongoid::Document  belongs_to :test1, class_name: "Test1"  field :format, type: Symbol
      end
      
      t1=Test1.create
      t2=Test2.create(test1: t1, format: :html)
      t2.format # => :html
      t2.send(:format) # => :html
      
      t1.reload
      t1.test2.format # => :html
      t1.test2.send(:format)
      # =>
      # ArgumentError: too few arguments
      # from (pry):18:in `format'
      
      

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            thomaskuntz67@gmail.com Thomas Kuntz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: