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

#create and #new are not using the default scope. Bug or feature?

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

      ActiveRecord uses the default_scope in the new and create operation by default, but Mongoid does not. Is this intended, or should it behave the same way than ActiveRecord?

      From ActiveRecord's documentation :

      >The default_scope is also applied while creating/building a record. It is not applied while updating a record.

      class Article < ActiveRecord::Base
        default_scope where(:published => true)
      end
      >
      Article.new.published    # => true
      Article.create.published # => true
      

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

              Created:
              Updated:
              Resolved: