Mongoid::Paranoiaã§è«çåé¤ããããã¥ã¡ã³ããä¸ç·ããã«åãåããã
hatena.vimã®åä½ç¢ºèªãå ¼ãã¦ã
unscoped ã§è«çåé¤ããããã®ãå¼ã£å¼µã£ã¦ããããã¨æã£ããéã£ãã
# mongoid-2.0.2/lib/mongoid/paranoia.rb <ä¸ç¥...> module ClassMethods #:nodoc: # Override the default +Criteria+ accessor to only get existing # documents. Passes all arguments up to +NamedScope.criteria+ # # Returns: # # A +Criteria+ for deleted_at not existing. def criteria(*args) super.where(:deleted_at.exists => false) end # Find deleted documents # # Examples: # # <tt>Person.deleted</tt> # all deleted employees # <tt>Company.first.employees.deleted</tt> # works with a join # <tt>Person.deleted.find("4c188dea7b17235a2a000001").first</tt> def deleted where(:deleted_at.exists => true) end end <ä¸ç¥...>
Mongoid::Paranoiaã使ãã¨criteriaãä¸æ¸ãããããã§ãããã ãã unscoped ã¨ããã¦ãã ãã ã£ãã®ãã
åé¤ããããã®ã¯ deleted ã§åãããã©ãè«çåé¤é¢ä¿ãªãåãåãããã¨ãã¯ã©ããããã ããã
module Mongoid::Paranoia::ClassMethods def with_deleted c = criteria c.selector.clear c end end
足ãã¦ãã®å ´ããã®ãã ã