deep_pluck 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deep_pluck/model.rb +10 -9
- data/lib/deep_pluck/version.rb +1 -1
- 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: 44d38789b1249442a2a97cf7206309ce2a5125e3
|
4
|
+
data.tar.gz: 5e07435ba363c3fbe2a325dc8cd1fec1791228b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44b321b33fdadcefd60a4d1b2319c8b03cb57cd2331888921f7082b830bc664a1d3d66e9533b0f0f12b70a7991b3da888aedb11e68e7532463604a7f5a6c66bc
|
7
|
+
data.tar.gz: c28edcfd210948743d1e883f44d2e40f73db88ae92f05d8efd48e423006566e6c5903f3f255688e609438852a6306bec8725b13d968d636165a23aa8d827e128
|
data/lib/deep_pluck/model.rb
CHANGED
@@ -14,12 +14,12 @@ module DeepPluck
|
|
14
14
|
# Reader
|
15
15
|
#---------------------------------------
|
16
16
|
def reflect_on_association(association_key)
|
17
|
-
@relation.klass.reflect_on_association(association_key)
|
17
|
+
@relation.klass.reflect_on_association(association_key.to_sym) #add to_sym since rails 3 only support symbol
|
18
18
|
end
|
19
19
|
def get_foreign_key(association_key, reverse = false)
|
20
20
|
reflect = reflect_on_association(association_key)
|
21
|
-
return (reflect.belongs_to? ?
|
22
|
-
return (reflect.belongs_to? ? reflect.foreign_key :
|
21
|
+
return (reflect.belongs_to? ? @relation.klass.primary_key : reflect.foreign_key) if reverse
|
22
|
+
return (reflect.belongs_to? ? reflect.foreign_key : @relation.klass.primary_key)
|
23
23
|
end
|
24
24
|
#---------------------------------------
|
25
25
|
# Contruction OPs
|
@@ -81,15 +81,16 @@ module DeepPluck
|
|
81
81
|
all_need_columns = [*prev_need_columns, *next_need_columns, *@need_columns].uniq
|
82
82
|
@extra_columns = all_need_columns - @need_columns
|
83
83
|
@relation = yield(@relation) if block_given?
|
84
|
-
|
85
|
-
end
|
86
|
-
def load_all
|
87
|
-
data = load_data
|
84
|
+
@data = @relation.pluck_all(*all_need_columns)
|
88
85
|
@associations.each do |key, model|
|
89
|
-
set_includes_data(data, key, model)
|
86
|
+
set_includes_data(@data, key, model)
|
90
87
|
end
|
88
|
+
return @data
|
89
|
+
end
|
90
|
+
def load_all
|
91
|
+
load_data
|
91
92
|
delete_extra_column_data!
|
92
|
-
return data
|
93
|
+
return @data
|
93
94
|
end
|
94
95
|
def delete_extra_column_data!
|
95
96
|
@data.each{|s| s.except!(*@extra_columns) } if @data
|
data/lib/deep_pluck/version.rb
CHANGED