active_record_patch_first_or_create 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e92935b4898babaff9fd4e5718a89a0f3102aa4
|
4
|
+
data.tar.gz: 4cf0be332d15edce5a7623d0a50856c546dd5361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fcad1d4e14080377aab151140eba1fbac162c281d680c85c945afc584ac18f9a329445302a24a961be926693d5d111b08b603bec79526058415b220e2a61299
|
7
|
+
data.tar.gz: a1d21c7303e3b1b5a4c57772714a146ff8042b4129fe69f7af416d14ff8affd7919cac62fdcd951d741e6c5d92258ecaa555bef86826f0214f01db00c3d75a66
|
@@ -2,13 +2,18 @@ require "active_record_patch_first_or_create/version"
|
|
2
2
|
require "active_record_patch_first_or_create/arel_query_creator"
|
3
3
|
|
4
4
|
module ActiveRecordPatchFirstOrCreate
|
5
|
-
def self.first_or_create relation, attributes
|
5
|
+
def self.first_or_create relation, attributes, tries=nil
|
6
6
|
|
7
7
|
attributes = attributes.merge(relation.where_values_hash)
|
8
8
|
attributes = attributes.merge(rails_timestamps(relation))
|
9
9
|
attributes = serialize_columns(relation, attributes)
|
10
10
|
|
11
|
-
|
11
|
+
begin
|
12
|
+
ActiveRecord::Base.connection.execute(ArelQueryCreator.new(relation, attributes).to_sql)
|
13
|
+
# Rescue first time that gives RecordNotUnique because:
|
14
|
+
# http://www.postgresql.org/message-id/26970.1296761016@sss.pgh.pa.us
|
15
|
+
rescue ActiveRecord::RecordNotUnique
|
16
|
+
end
|
12
17
|
|
13
18
|
relation.first
|
14
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_patch_first_or_create
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NDrive DevOps Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,9 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.4.
|
147
|
+
rubygems_version: 2.4.5
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: ActiveRecord patch first_or_create atomic version
|
151
151
|
test_files: []
|
152
|
-
has_rdoc:
|