composite_primary_keys 10.0.1 → 10.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +6 -0
- data/lib/composite_primary_keys.rb +3 -1
- data/lib/composite_primary_keys/autosave_association.rb +32 -0
- data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/test_associations.rb +10 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 747335fa1b0ec3dec3bf8747c73154e7315b3adf
|
4
|
+
data.tar.gz: 4717b2d1fa29a60085a1a7555775acbd330aa700
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c692686ba13178d1965f53d37aa40fa10cabe399312b1281a1834d4f8b9f4c971e984daffbb89836779946d499f4648e73b665bc9a99060e27b6413ee99494c0
|
7
|
+
data.tar.gz: 4bfc14d692903f6f9c00c13c2522e84900c860b457011c11f9210a7d11f8b0285bb285e21bb437510fd320897cc56a3f1cadbcffbd8f4b2021777765f0ffb6fd
|
data/History.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 10.0.2 (2017-12-02)
|
2
|
+
|
3
|
+
* Fix frozen string mutation for mysql (Sergey Sein)
|
4
|
+
* Fix autosave for belongs_to associations (Fabian Mersch)
|
5
|
+
* Require a minimum of activerecord version 5.1.4 (Charlie Savage)
|
6
|
+
|
1
7
|
== 10.0.1 (2017-10-08)
|
2
8
|
|
3
9
|
* Fixed an error that happened when a table attribute had the same name as the table (Taishi Kasuga)
|
@@ -26,7 +26,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
26
26
|
|
27
27
|
unless defined?(ActiveRecord)
|
28
28
|
require 'rubygems'
|
29
|
-
gem 'activerecord', '~>5.1.0'
|
29
|
+
gem 'activerecord', ['~>5.1.0', '>= 5.1.4']
|
30
30
|
require 'active_record'
|
31
31
|
end
|
32
32
|
|
@@ -38,6 +38,7 @@ require 'active_record/persistence'
|
|
38
38
|
require 'active_record/relation'
|
39
39
|
require 'active_record/sanitization'
|
40
40
|
require 'active_record/attribute_methods'
|
41
|
+
require 'active_record/autosave_association'
|
41
42
|
|
42
43
|
require 'active_record/associations/association'
|
43
44
|
require 'active_record/associations/association_scope'
|
@@ -78,6 +79,7 @@ require 'composite_primary_keys/relation'
|
|
78
79
|
require 'composite_primary_keys/sanitization'
|
79
80
|
require 'composite_primary_keys/attribute_set/builder'
|
80
81
|
require 'composite_primary_keys/attribute_methods'
|
82
|
+
require 'composite_primary_keys/autosave_association'
|
81
83
|
require 'composite_primary_keys/version'
|
82
84
|
|
83
85
|
require 'composite_primary_keys/associations/association'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module AutosaveAssociation
|
3
|
+
private
|
4
|
+
|
5
|
+
def save_belongs_to_association(reflection)
|
6
|
+
association = association_instance_get(reflection.name)
|
7
|
+
return unless association && association.loaded? && !association.stale_target?
|
8
|
+
|
9
|
+
record = association.load_target
|
10
|
+
if record && !record.destroyed?
|
11
|
+
autosave = reflection.options[:autosave]
|
12
|
+
|
13
|
+
if autosave && record.marked_for_destruction?
|
14
|
+
self[reflection.foreign_key] = nil
|
15
|
+
record.destroy
|
16
|
+
elsif autosave != false
|
17
|
+
saved = record.save(validate: !autosave) if record.new_record? || (autosave && record.changed_for_autosave?)
|
18
|
+
|
19
|
+
if association.updated?
|
20
|
+
# CPK
|
21
|
+
# association_id = record.send(reflection.options[:primary_key] || :id)
|
22
|
+
association_id = reflection.options[:primary_key] ? record[reflection.options[:primary_key]] : record.id
|
23
|
+
self[reflection.foreign_key] = association_id
|
24
|
+
association.loaded!
|
25
|
+
end
|
26
|
+
|
27
|
+
saved if autosave
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -7,7 +7,7 @@ module ActiveRecord
|
|
7
7
|
# quoted_pk = SQLServer::Utils.extract_identifiers(pk).quoted
|
8
8
|
# sql.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk}"
|
9
9
|
quoted_pks = [pk].flatten.map {|pk| "INSERTED.#{SQLServer::Utils.extract_identifiers(pk).quoted}"}
|
10
|
-
sql.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT #{quoted_pks.join(", ")}"
|
10
|
+
sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT #{quoted_pks.join(", ")}"
|
11
11
|
else
|
12
12
|
"#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
|
13
13
|
end
|
data/test/test_associations.rb
CHANGED
@@ -71,6 +71,16 @@ class TestAssociations < ActiveSupport::TestCase
|
|
71
71
|
assert_equal(3, tariffs.inject(0) {|sum, tariff| sum + tariff.product_tariffs.length})
|
72
72
|
end
|
73
73
|
|
74
|
+
def test_association_with_composite_primary_key_can_be_autosaved
|
75
|
+
room = Room.new(dorm_id: 1000, room_id: 1001)
|
76
|
+
room_assignment = RoomAssignment.new(student_id: 1000)
|
77
|
+
room_assignment.room = room
|
78
|
+
room_assignment.save
|
79
|
+
room_assignment.reload
|
80
|
+
assert_equal(room_assignment.dorm_id, 1000)
|
81
|
+
assert_equal(room_assignment.room_id, 1001)
|
82
|
+
end
|
83
|
+
|
74
84
|
def test_has_one_association_is_not_cached_to_where_it_returns_the_wrong_one
|
75
85
|
engineering = departments(:engineering)
|
76
86
|
engineering_head = engineering.head
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.0.
|
4
|
+
version: 10.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 5.1.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.1.4
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 5.1.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.4
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +113,7 @@ files:
|
|
107
113
|
- lib/composite_primary_keys/attribute_methods/read.rb
|
108
114
|
- lib/composite_primary_keys/attribute_methods/write.rb
|
109
115
|
- lib/composite_primary_keys/attribute_set/builder.rb
|
116
|
+
- lib/composite_primary_keys/autosave_association.rb
|
110
117
|
- lib/composite_primary_keys/base.rb
|
111
118
|
- lib/composite_primary_keys/composite_arrays.rb
|
112
119
|
- lib/composite_primary_keys/composite_predicates.rb
|