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 +4 -4
- data/lib/sequence_on/sequenced_on.rb +12 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2650250c9ca169de3a4581fa0e2d07e44e61fe37
|
4
|
+
data.tar.gz: ff1a627e0a0d887a5dea4f84e46b567c871de144
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
26
|
-
|
27
|
-
|
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
|