deep_pluck 1.1.3 → 1.1.4

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
  SHA256:
3
- metadata.gz: 378081961b9290a5a9b980183be343f68dbc27c718d6b8b78ce579577a18c5b3
4
- data.tar.gz: 91a7eb4c989d257f85e9f59356e620d87a4ee0d3f408d0e7735152e629c51af1
3
+ metadata.gz: b7bbd3c0df3b323529a252d7d56fa596b4f85923b06b54a04560826b2793b8fe
4
+ data.tar.gz: 1261968870077b5cb7f4db0c56e1045f513b6caa2a76c028a9235535635704c5
5
5
  SHA512:
6
- metadata.gz: cae771fdd717b163da5d3f894b2e9025cb448f23565a32b1978a81da6419404998105718d493f2f0092727e9a06add477545648a53577b15efb58ddf7ab9027e
7
- data.tar.gz: 1f52ccf2d762ddd8e2c56117c2c62156bb5a30a98c86cd2df364c6be26c6f91fcefd7043fd265ce00b7a469c5e35ac3d47bf43878440cade9188af6c862701ce
6
+ metadata.gz: dd9196070fb6189bc2e2b8da44976fd0ecd5dead243075a8abe66ae524af674d1f8e99f74abb0d2337bf65e42f85688ef20ba07c4b422f0179750b50d35421d3
7
+ data.tar.gz: 34302f6ca57406fa7c61635fd0e2465cafef8b41da426b62f23fee1635df506a9d1750b2506653b0d307d2d1a599a83d23986ad9efc772c2ad66dd5792bdbef1
@@ -6,6 +6,7 @@ language: ruby
6
6
  rvm:
7
7
  - 2.2
8
8
  - 2.6
9
+ - 2.7
9
10
  gemfile:
10
11
  - gemfiles/3.2.gemfile
11
12
  - gemfiles/4.2.gemfile
@@ -17,13 +18,17 @@ matrix:
17
18
  exclude:
18
19
  - gemfile: gemfiles/3.2.gemfile
19
20
  rvm: 2.6
20
- - gemfile: gemfiles/4.0.gemfile
21
- rvm: 2.6
21
+ - gemfile: gemfiles/3.2.gemfile
22
+ rvm: 2.7
23
+ - gemfile: gemfiles/4.2.gemfile
24
+ rvm: 2.7
22
25
  - gemfile: gemfiles/6.0.gemfile
23
26
  rvm: 2.2
24
27
  before_install:
25
- - gem i rubygems-update -v '<3' && update_rubygems
26
- - gem install bundler -v 1.17.3
28
+ - if `ruby -e 'exit(RUBY_VERSION.to_f < 2.7)'`; then
29
+ gem i rubygems-update -v '< 3' && update_rubygems;
30
+ gem install bundler -v '< 2';
31
+ fi
27
32
  - gem --version
28
33
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
29
34
  - chmod +x ./cc-test-reporter
@@ -1,54 +1,59 @@
1
- ## Change Log
2
-
3
- ### [v1.1.2](https://github.com/khiav223577/deep_pluck/compare/v1.1.1...v1.1.2) 2019/09/25
4
- - [#32](https://github.com/khiav223577/deep_pluck/pull/32) Remove unneeded `PreloadedModel` (@khiav223577)
5
- - [#31](https://github.com/khiav223577/deep_pluck/pull/31) Support Rails 6.0 (@khiav223577)
6
- - [#30](https://github.com/khiav223577/deep_pluck/pull/30) Lock sqlite3 version to 1.3.x (@khiav223577)
7
- - [#28](https://github.com/khiav223577/deep_pluck/pull/28) Fix: broken test cases after bundler 2.0 was released (@khiav223577)
8
- - [#27](https://github.com/khiav223577/deep_pluck/pull/27) Remove deprecated codeclimate-test-reporter gem and update travis config (@khiav223577)
9
-
10
- ### [v1.1.1](https://github.com/khiav223577/deep_pluck/compare/v1.1.0...v1.1.1) 2018/07/08
11
- - [#26](https://github.com/khiav223577/deep_pluck/pull/26) Fix: `id` may disappear when plucking at model instance (@khiav223577)
12
- - [#25](https://github.com/khiav223577/deep_pluck/pull/25) Refactor - move models definition to separate files (@khiav223577)
13
- - [#24](https://github.com/khiav223577/deep_pluck/pull/24) test Rails 5.2 (@khiav223577)
14
- - [#23](https://github.com/khiav223577/deep_pluck/pull/23) should test both 5.0.x and 5.1.x (@khiav223577)
15
- - [#22](https://github.com/khiav223577/deep_pluck/pull/22) #deep_pluck at active model without plucking deeply will cause ArgumentError (@khiav223577)
16
- - [#20](https://github.com/khiav223577/deep_pluck/pull/20) [ENHANCE] Eliminate Extra Select Loop in Hash Lookup (@berniechiu)
17
-
18
- ### [v1.1.0](https://github.com/khiav223577/deep_pluck/compare/v1.0.3...v1.1.0) 2018/02/15
19
- - [#19](https://github.com/khiav223577/deep_pluck/pull/19) Support deep_pluck at active model (@khiav223577)
20
- - [#18](https://github.com/khiav223577/deep_pluck/pull/18) Add rubocop and Improve code quality (@khiav223577)
21
-
22
- ### [v1.0.3](https://github.com/khiav223577/deep_pluck/compare/v1.0.2...v1.0.3) 2017/06/30
23
- - [#15](https://github.com/khiav223577/deep_pluck/pull/15) test deep_pluck in rails 5.1.x (@khiav223577)
24
- - [#14](https://github.com/khiav223577/deep_pluck/pull/14) Handle polymorphic associations correctly. (@Bogadon)
25
-
26
- ### [v1.0.0](https://github.com/khiav223577/deep_pluck/compare/v0.1.4...v1.0.0) 2017/03/28
27
- - [#12](https://github.com/khiav223577/deep_pluck/pull/12) reduce cyclomatic complexity in model.rb (@khiav223577)
28
-
29
- ### [v0.1.4](https://github.com/khiav223577/deep_pluck/compare/v0.1.3...v0.1.4) 2017/03/27
30
- - [#11](https://github.com/khiav223577/deep_pluck/pull/11) Fix conditional associations (@khiav223577)
31
-
32
- ### [v0.1.3](https://github.com/khiav223577/deep_pluck/compare/v0.1.2...v0.1.3) 2017/03/20
33
- - [#10](https://github.com/khiav223577/deep_pluck/pull/10) fix custom foreign_key, custom primary_key issues (@khiav223577)
34
- - [#9](https://github.com/khiav223577/deep_pluck/pull/9) fix has_and_belongs_to_many (@khiav223577)
35
-
36
- ### [v0.1.2](https://github.com/khiav223577/deep_pluck/compare/v0.1.1...v0.1.2) 2017/03/17
37
- - [#8](https://github.com/khiav223577/deep_pluck/pull/8) fix some need columns is missing (@khiav223577)
38
- - [#7](https://github.com/khiav223577/deep_pluck/pull/7) raise error message when association not found (@khiav223577)
39
-
40
- ### [v0.1.1](https://github.com/khiav223577/deep_pluck/compare/v0.1.0...v0.1.1) 2017/03/16
41
- - [#6](https://github.com/khiav223577/deep_pluck/pull/6) fix deep_pluck with #joins (@khiav223577)
42
-
43
- ### [v0.1.0](https://github.com/khiav223577/deep_pluck/compare/v0.0.4...v0.1.0) 2017/03/15
44
- - [#5](https://github.com/khiav223577/deep_pluck/pull/5) Support pluck many-to-many associations (@khiav223577)
45
-
46
- ### [v0.0.4](https://github.com/khiav223577/deep_pluck/compare/v0.0.3...v0.0.4) 2017/03/14
47
- - [#4](https://github.com/khiav223577/deep_pluck/pull/4) Fix use deep_pluck on NullRelation will raise exception and prevent unneeded query. (@khiav223577)
48
-
49
- ### [v0.0.3](https://github.com/khiav223577/deep_pluck/compare/v0.0.2...v0.0.3) 2017/03/06
50
- - [#3](https://github.com/khiav223577/deep_pluck/pull/3) support more than two level (@khiav223577)
51
-
52
- ### [v0.0.2](https://github.com/khiav223577/deep_pluck/compare/v0.0.1...v0.0.2) 2017/03/06
53
- - [#2](https://github.com/khiav223577/deep_pluck/pull/2) The result of has_one association should not be array (@khiav223577)
54
- - [#1](https://github.com/khiav223577/deep_pluck/pull/1) deep pluck (@khiav223577)
1
+ ## Change Log
2
+
3
+ ### [v1.1.3](https://github.com/khiav223577/deep_pluck/compare/v1.1.2...v1.1.3) 2019/12/17
4
+ - [#34](https://github.com/khiav223577/deep_pluck/pull/34) Support for plucking directly on a has_one through association (@khiav223577)
5
+
6
+ ### [v1.1.2](https://github.com/khiav223577/deep_pluck/compare/v1.1.1...v1.1.2) 2019/09/25
7
+ - [#32](https://github.com/khiav223577/deep_pluck/pull/32) Remove unneeded `PreloadedModel` (@khiav223577)
8
+ - [#31](https://github.com/khiav223577/deep_pluck/pull/31) Support Rails 6.0 (@khiav223577)
9
+ - [#30](https://github.com/khiav223577/deep_pluck/pull/30) Lock sqlite3 version to 1.3.x (@khiav223577)
10
+ - [#28](https://github.com/khiav223577/deep_pluck/pull/28) Fix: broken test cases after bundler 2.0 was released (@khiav223577)
11
+ - [#27](https://github.com/khiav223577/deep_pluck/pull/27) Remove deprecated codeclimate-test-reporter gem and update travis config (@khiav223577)
12
+
13
+ ### [v1.1.1](https://github.com/khiav223577/deep_pluck/compare/v1.1.0...v1.1.1) 2018/07/08
14
+ - [#26](https://github.com/khiav223577/deep_pluck/pull/26) Fix: `id` may disappear when plucking at model instance (@khiav223577)
15
+ - [#25](https://github.com/khiav223577/deep_pluck/pull/25) Refactor - move models definition to separate files (@khiav223577)
16
+ - [#24](https://github.com/khiav223577/deep_pluck/pull/24) test Rails 5.2 (@khiav223577)
17
+ - [#23](https://github.com/khiav223577/deep_pluck/pull/23) should test both 5.0.x and 5.1.x (@khiav223577)
18
+ - [#22](https://github.com/khiav223577/deep_pluck/pull/22) #deep_pluck at active model without plucking deeply will cause ArgumentError (@khiav223577)
19
+ - [#20](https://github.com/khiav223577/deep_pluck/pull/20) [ENHANCE] Eliminate Extra Select Loop in Hash Lookup (@berniechiu)
20
+
21
+ ### [v1.1.0](https://github.com/khiav223577/deep_pluck/compare/v1.0.3...v1.1.0) 2018/02/15
22
+ - [#19](https://github.com/khiav223577/deep_pluck/pull/19) Support deep_pluck at active model (@khiav223577)
23
+ - [#18](https://github.com/khiav223577/deep_pluck/pull/18) Add rubocop and Improve code quality (@khiav223577)
24
+
25
+ ### [v1.0.3](https://github.com/khiav223577/deep_pluck/compare/v1.0.2...v1.0.3) 2017/06/30
26
+ - [#15](https://github.com/khiav223577/deep_pluck/pull/15) test deep_pluck in rails 5.1.x (@khiav223577)
27
+ - [#14](https://github.com/khiav223577/deep_pluck/pull/14) Handle polymorphic associations correctly. (@Bogadon)
28
+
29
+ ### [v1.0.0](https://github.com/khiav223577/deep_pluck/compare/v0.1.4...v1.0.0) 2017/03/28
30
+ - [#12](https://github.com/khiav223577/deep_pluck/pull/12) reduce cyclomatic complexity in model.rb (@khiav223577)
31
+
32
+ ### [v0.1.4](https://github.com/khiav223577/deep_pluck/compare/v0.1.3...v0.1.4) 2017/03/27
33
+ - [#11](https://github.com/khiav223577/deep_pluck/pull/11) Fix conditional associations (@khiav223577)
34
+
35
+ ### [v0.1.3](https://github.com/khiav223577/deep_pluck/compare/v0.1.2...v0.1.3) 2017/03/20
36
+ - [#10](https://github.com/khiav223577/deep_pluck/pull/10) fix custom foreign_key, custom primary_key issues (@khiav223577)
37
+ - [#9](https://github.com/khiav223577/deep_pluck/pull/9) fix has_and_belongs_to_many (@khiav223577)
38
+
39
+ ### [v0.1.2](https://github.com/khiav223577/deep_pluck/compare/v0.1.1...v0.1.2) 2017/03/17
40
+ - [#8](https://github.com/khiav223577/deep_pluck/pull/8) fix some need columns is missing (@khiav223577)
41
+ - [#7](https://github.com/khiav223577/deep_pluck/pull/7) raise error message when association not found (@khiav223577)
42
+
43
+ ### [v0.1.1](https://github.com/khiav223577/deep_pluck/compare/v0.1.0...v0.1.1) 2017/03/16
44
+ - [#6](https://github.com/khiav223577/deep_pluck/pull/6) fix deep_pluck with #joins (@khiav223577)
45
+
46
+ ### [v0.1.0](https://github.com/khiav223577/deep_pluck/compare/v0.0.4...v0.1.0) 2017/03/15
47
+ - [#5](https://github.com/khiav223577/deep_pluck/pull/5) Support pluck many-to-many associations (@khiav223577)
48
+
49
+ ### [v0.0.4](https://github.com/khiav223577/deep_pluck/compare/v0.0.3...v0.0.4) 2017/03/14
50
+ - [#4](https://github.com/khiav223577/deep_pluck/pull/4) Fix use deep_pluck on NullRelation will raise exception and prevent unneeded query. (@khiav223577)
51
+
52
+ ### [v0.0.3](https://github.com/khiav223577/deep_pluck/compare/v0.0.2...v0.0.3) 2017/03/06
53
+ - [#3](https://github.com/khiav223577/deep_pluck/pull/3) support more than two level (@khiav223577)
54
+
55
+ ### [v0.0.2](https://github.com/khiav223577/deep_pluck/compare/v0.0.1...v0.0.2) 2017/03/06
56
+ - [#2](https://github.com/khiav223577/deep_pluck/pull/2) The result of has_one association should not be array (@khiav223577)
57
+
58
+ ### v0.0.1 2017/03/04
59
+ - [#1](https://github.com/khiav223577/deep_pluck/pull/1) deep pluck (@khiav223577)
data/README.md CHANGED
@@ -8,8 +8,9 @@
8
8
 
9
9
  Allow you to pluck deeply into nested associations without loading a bunch of records.
10
10
 
11
- Support Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0.
12
-
11
+ ## Supports
12
+ - Ruby 2.2 ~ 2.7
13
+ - Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0
13
14
 
14
15
  ## Installation
15
16
 
@@ -119,7 +119,23 @@ module DeepPluck
119
119
  query[reflect.type] = reflect.active_record.to_s if reflect.type
120
120
 
121
121
  return get_association_scope(reflect).where(query) if use_association_to_query?(reflect)
122
- return relation.joins(get_join_table(reflect)).where(query)
122
+
123
+ join_table = get_join_table(reflect)
124
+ join_table = backtrace_possible_association(relation, join_table)
125
+
126
+ return relation.joins(join_table).where(query)
127
+ end
128
+
129
+ # Let city has_many :users, through: :schools
130
+ # And the query is: City.deep_pluck('users' => :name)
131
+ # We want to get the users data via `User.joins(:school).where(city_id: city_ids)`
132
+ # But get_join_table(reflect) returns `:schools` not :school
133
+ # No idea how to get the right association, so we try singularize or pluralize it.
134
+ def backtrace_possible_association(relation, join_table)
135
+ return join_table if relation.reflect_on_association(join_table)
136
+ join_table.to_s.singularize.to_sym.tap{|s| return s if relation.reflect_on_association(s) }
137
+ join_table.to_s.pluralize.to_sym.tap{|s| return s if relation.reflect_on_association(s) }
138
+ return nil
123
139
  end
124
140
 
125
141
  def set_includes_data(parent, column_name, model)
@@ -1,3 +1,3 @@
1
1
  module DeepPluck
2
- VERSION = '1.1.3'
2
+ VERSION = '1.1.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_pluck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2020-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler