Sha256: 2d13f0f270b9493ae2692b80aa8e466792f8201572c950e40e2c72ac9d8d7ed7

Contents?: true

Size: 651 Bytes

Versions: 1

Compression:

Stored size: 651 Bytes

Contents

module Mongoid::Criterion::Optional
  #
  # Overwrite the id method to find objects
  # by the specified slug rather than the id.
  # If you want to find via id you'll have to use
  # An explicit finder like:
  #
  #   where(:_id => some_id)
  #
  alias :id! :id
  def id(*ids)
    unless ids.first.is_a?(BSON::ObjectId)
      ids.flatten!
      if ids.size > 1
        self.in(
        @klass.acts_as_slugoid_options[:store_as] => ::BSON::ObjectId.cast!(@klass, ids, @klass.primary_key.nil?)
        )
      else
        @selector[@klass.acts_as_slugoid_options[:store_as]] = ids.first
      end
      self
    else
      id!(*ids)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slugoid-0.0.5 lib/slugoid/mongoid/criterion/optional.rb