Sha256: 7a13d73b0b31eae703ad3e8be50ad654aa7fe6e77271c2af0098d0c9a9ed07af

Contents?: true

Size: 665 Bytes

Versions: 1

Compression:

Stored size: 665 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)
    if @klass.respond_to?(:acts_as_sluggable_options)
      ids.flatten!
      if ids.size > 1
        self.in(
        @klass.acts_as_sluggable_options[:store_as] => ::BSON::ObjectId.cast!(@klass, ids, @klass.primary_key.nil?)
        )
      else
        @selector[@klass.acts_as_sluggable_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
acts_as_sluggable-0.0.3 lib/acts_as_sluggable/mongoid/criterion/optional.rb