Class: Mongoid::Sequences
- Inherits:
-
Object
- Object
- Mongoid::Sequences
- Includes:
- Document
- Defined in:
- lib/mongoid-sequence2/sequences.rb
Class Method Summary collapse
- .get_next_sequence(collection, fieldname, step = 1) ⇒ Object
- .get_sequence(collection, fieldname) ⇒ Object
Class Method Details
.get_next_sequence(collection, fieldname, step = 1) ⇒ Object
10 11 12 13 |
# File 'lib/mongoid-sequence2/sequences.rb', line 10 def self.get_next_sequence(collection, fieldname, step = 1) step ||= 1 self.where(fieldname: "#{collection}_#{fieldname}").find_and_modify({'$inc' => {'seq' => step}}, {'upsert' => 'true', :new => true}).seq end |
.get_sequence(collection, fieldname) ⇒ Object
15 16 17 |
# File 'lib/mongoid-sequence2/sequences.rb', line 15 def self.get_sequence(collection, fieldname) seq = self.where(fieldname: "#{collection}_#{fieldname}").limit(1).first.try(:seq) || 1 end |