Module: Mongoid::Criterion::Optional
- Defined in:
- lib/acts_as_sluggable/mongoid/criterion/optional.rb
Instance Method Summary collapse
- #id(*ids) ⇒ Object
-
#id! ⇒ Object
Overwrite the id method to find objects by the specified slug rather than the id.
Instance Method Details
#id(*ids) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/acts_as_sluggable/mongoid/criterion/optional.rb', line 11 def id(*ids) if @klass.respond_to?(:acts_as_sluggable_options) ids.flatten! if ids.size > 1 self.in( @klass.[:store_as] => ::BSON::ObjectId.cast!(@klass, ids, @klass.primary_key.nil?) ) else @selector[@klass.[:store_as]] = ids.first end self else id!(*ids) end end |
#id! ⇒ Object
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)
10 |
# File 'lib/acts_as_sluggable/mongoid/criterion/optional.rb', line 10 alias :id! :id |