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

With #only limitation, other fields return default value (if present), instead of nil

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.4
    • Affects Version/s: None
    • Component/s: None

      So, if we have document:

      class Person
        include Mongoid::Document
        field :name
        field :surname, default: 'Smith'
        field :age, type: Integer
      end
      

      Then

      Person.create name: 'James', surname: 'Bond', age: 45
      man_without_name = Person.only(:age).first
      man_without_name.age  #=> 45
      man_without_name.name  #=> nil
      man_without_name.surname  #=>  'Smith'
      

      I think all fields with default value in this case should return nil, as for fields without default value.

            Assignee:
            durran Durran Jordan
            Reporter:
            mik-die Mikhail Dieterle
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: