activerecord-belongs_to_if 0.0.4 → 0.1.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6796349f183521b9cff4226df8fd7598b41b8116
|
4
|
+
data.tar.gz: 6b40fb266cee832d080186b6a84c467af184fbec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f09841658c576895e6afaf3b185bcafa39804aeffc5b8d1e94404e8d3bc7166e5f88013b77adae9753e7f75d88c5184c8bb30519be71511bf1b42a80d1c5d50
|
7
|
+
data.tar.gz: 30c4e6be29eca223e738afbdf64bc512ef62a0c6e52b162f406c99e3744bcf16a01799bce3f08c6955396343509908e3b0cd2378725a0a4e55c0a705d9a0e883
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module BelongsToIf
|
3
3
|
module BuilderExtension
|
4
|
+
# To keep compatibility with Rails > 4
|
4
5
|
def valid_options
|
5
6
|
super + [:if]
|
6
7
|
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def valid_options(options)
|
11
|
+
super + [:if]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.prepended(base)
|
16
|
+
class << base
|
17
|
+
prepend ClassMethods
|
18
|
+
end
|
19
|
+
end
|
7
20
|
end
|
8
21
|
end
|
9
22
|
end
|
@@ -28,28 +28,40 @@ module ActiveRecord
|
|
28
28
|
|
29
29
|
# @note Override to change `records_by_owner` so that empty array is used.
|
30
30
|
def associated_records_by_owner(preloader)
|
31
|
-
owners_map = owners_by_key
|
32
|
-
owner_keys = owners_map.keys.compact
|
33
|
-
|
34
31
|
# Each record may have multiple owners, and vice-versa
|
35
32
|
records_by_owner = Hash.new do |hash, key|
|
36
33
|
hash[key] = []
|
37
34
|
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
# To keep compatibility with Rails > 4
|
37
|
+
if ::ActiveRecord::VERSION::MAJOR > 4
|
38
|
+
records = load_records
|
39
|
+
records_by_owner = Hash.new do |hash, key|
|
40
|
+
hash[key] = []
|
41
|
+
end
|
42
|
+
owners.each_with_object(records_by_owner) do |owner, result|
|
43
|
+
result[owner] = records[convert_key(owner[owner_key_name])] || []
|
44
|
+
end
|
45
|
+
else
|
46
|
+
owners_map = owners_by_key
|
47
|
+
owner_keys = owners_map.keys.compact
|
48
|
+
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
if owner_keys.any?
|
51
|
+
# Some databases impose a limit on the number of ids in a list (in Oracle it's 1000)
|
52
|
+
# Make several smaller queries if necessary or make one query if the adapter supports it
|
53
|
+
sliced = owner_keys.each_slice(klass.connection.in_clause_length || owner_keys.size)
|
54
|
+
|
55
|
+
records = load_slices sliced
|
56
|
+
records.each do |record, owner_key|
|
57
|
+
owners_map[owner_key].each do |owner|
|
58
|
+
records_by_owner[owner] << record
|
59
|
+
end
|
48
60
|
end
|
49
61
|
end
|
50
|
-
end
|
51
62
|
|
52
|
-
|
63
|
+
records_by_owner
|
64
|
+
end
|
53
65
|
end
|
54
66
|
|
55
67
|
# @return [Proc, String, Symbol, nil] The value :if option passed to belongs_to.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-belongs_to_if
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -105,9 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.4.5
|
108
|
+
rubygems_version: 2.4.5.1
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Allows you to manage preload condition by `:if` condition.
|
112
112
|
test_files: []
|
113
|
-
has_rdoc:
|