Proposal: #first_or_new method

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • 4.0.0 final
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently we have first_or_create and first_or_initialize. Both of these methods pick apart the query criteria and attempt to mass-assign attributes.

      Often my query contains non-mass-assignable attributes, which gives warnings. I'd prefer to have a much simpler method first_or_new like so:

      module Mongoid
        module Document
          module ClassMethods
            def first_or_new(attrs = {})
              first || self.new(attrs)
            end
          end
        end
      end
      

            Assignee:
            Unassigned
            Reporter:
            Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: