sequence_on 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9618c3be5bdea726ff10c71a2b1c7c4defcb6b14
4
- data.tar.gz: 44a9661efd046a062dd1ca4a7ffdea7138fdbe65
3
+ metadata.gz: 2650250c9ca169de3a4581fa0e2d07e44e61fe37
4
+ data.tar.gz: ff1a627e0a0d887a5dea4f84e46b567c871de144
5
5
  SHA512:
6
- metadata.gz: 9ea215f9c02ab3a675a16d00b9a062d0edbd679e64d4f5696d302bc85747efdab85d18ace4afa5b912d473eae2ea4f14606788ad389c7ae32784f287ab0b8257
7
- data.tar.gz: 22b50a14f3ae5270e668e9cab3c696c7026d58a97fab3964930a460cd792876bf55cd3107b966410c2c0d6be76992ed8ffe5a9bd1a2d0e40964245b296d13294
6
+ metadata.gz: 91548be69e31db59c00f2b252276ed13ac2080c747df387ed4bdc1bd32faf73e95c58ca1cde6eb7971a12760c100d9794ec12b4f45416ec4cc27e15027365ed9
7
+ data.tar.gz: 07db90399a320135bb17a07a645eca0f1abc2728ef42a593a73218b9ef30943b8b5220cdb6fd5a146e0db4bcff52fb5c3bf4f9f2c79470c5a76cc6c39d348eef
@@ -20,11 +20,20 @@ module SequenceOn
20
20
  end
21
21
 
22
22
  def generate_sequence_id
23
+ return if self.sequential_id
23
24
  options = self.class.sequence_options
24
25
  self.class.connection.execute("LOCK TABLE #{self.class.table_name} IN EXCLUSIVE MODE") if postgresql?
25
- last_record = self.class.class_exec(self, &options[:lmd]).
26
- order("#{options[:column]} DESC").
27
- first
26
+ last_record = if record.persisted?
27
+ self.class.class_exec(self, &options[:lmd]).
28
+ order("#{options[:column]} DESC").
29
+ where("NOT id = ?", self.id).
30
+ first
31
+ else
32
+ self.class.class_exec(self, &options[:lmd]).
33
+ order("#{options[:column]} DESC").
34
+ first
35
+ end
36
+
28
37
  self.sequential_id = if last_record
29
38
  last_record.send(options[:column]) + 1
30
39
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequence_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy SEBAN