lib/saasable/mongoid/scoped_document.rb in saasable-0.3.5 vs lib/saasable/mongoid/scoped_document.rb in saasable-4.0.0
- old
+ new
@@ -6,14 +6,18 @@
klass.extend ClassMethods
klass.class_eval do
# Fields
field :saas_id, :type => BSON::ObjectId
-
+
# Indexes
- index :saas_id
- index [[:saad_id, 1], [:_id, 1]]
+ index({saas_id: 1})
+ index({saad_id: 1, _id: 1})
+
+ class << self
+ alias_method_chain :index, :saasable
+ end
end
end
def self.scoped_documents
@scoped_documents
@@ -31,9 +35,14 @@
def validates_uniqueness_of(*args)
attributes = _merge_attributes(args)
attributes[:scope] ||= []
attributes[:scope] << :saas_id unless attributes[:scope].include?(:saas_id)
- validates_with(Mongoid::Validations::UniquenessValidator, attributes)
+ validates_with(Mongoid::Validatable::UniquenessValidator, attributes)
+ end
+
+ def index_with_saasable(spec, options = nil)
+ index_without_saasable(spec, options.except(:unique)) # Never create this one with unique since it's only unique in the saas scope.
+ index_without_saasable({saas_id: 1}.merge(spec), options) unless spec.include?(:saas_id)
end
end
end