rails_select_on_includes 0.5.6 → 0.5.7
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 +4 -4
- data/README.md +29 -18
- data/Rakefile +8 -1
- data/lib/rails_select_on_includes.rb +7 -7
- data/lib/rails_select_on_includes/version.rb +1 -1
- data/rails_select_on_includes.gemspec +4 -0
- metadata +45 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58c0c965a81e2298fa093659f4b8cd490987b7ba
|
4
|
+
data.tar.gz: 40f53bca05f1f013bd7757702bb378db03bcbd21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cf96d2b09cafac42251f840afb79f7fcabbb60f6ab7d51642d1a26014cf3563390064e6f77454a70983df04eba1132801a989af3c84a87b0b3527d60af4726f
|
7
|
+
data.tar.gz: 3b9381419cf0f8d44bc9cc23b8088016863b3c7759cf37fcf04c2ad8f48238b34123ba2314e2f684b0e99f6b3368d78a2d83b92c6d0841975c8b6bdf2a13457a
|
data/README.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
+
# New Features
|
2
|
+
Selected virtual attributes will be now typecasted as usual attributes
|
3
|
+
|
4
|
+
#Rails version
|
5
|
+
Supports rails 4.x and rails 5 now!
|
6
|
+
Maser is now runs on 5.x, rails_4 branch is for rails 4 support
|
7
|
+
|
1
8
|
# RailsSelectOnIncludes
|
2
9
|
|
3
|
-
This gem solves issue in rails: https://github.com/rails/rails/issues/15185 for base_class.
|
10
|
+
This gem solves issue in rails: https://github.com/rails/rails/issues/15185 for base_class.
|
4
11
|
|
5
12
|
It was impossible to select virtual attributes to object from its relations or any other way
|
6
|
-
when using includes and where.
|
13
|
+
when using includes and where ( actually when includes becomes eager_load, i.e. when you add not SOME_CONDITION, but SOME_CONDITION_ON_INCLUDES, http://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html ).
|
7
14
|
|
8
15
|
Example from upper rails issue:
|
9
16
|
|
@@ -30,7 +37,7 @@ post.comments.first.testval # Undefined method!
|
|
30
37
|
|
31
38
|
Данный gem решает проблему в рельсах с виртуальными аттрибутами при использовании includes,
|
32
39
|
когда рельсы собирают в запрос в joins с алиасами на все аттрибуты. В настоящий момент в модель не собираются
|
33
|
-
никаким боком виртуальные
|
40
|
+
никаким боком виртуальные аттрибуты ( имеется ввиду когда includes ведет себя как eager_load и создает сложный одинарный запрос, подробнее: http://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html ).
|
34
41
|
|
35
42
|
В частности проблема описана здесь: https://github.com/rails/rails/issues/15185
|
36
43
|
|
@@ -56,12 +63,16 @@ post.comments.first.testval # Undefined method!
|
|
56
63
|
```
|
57
64
|
|
58
65
|
|
59
|
-
## Installation
|
66
|
+
## Installation
|
60
67
|
|
61
68
|
Add this line to your application's Gemfile:
|
62
69
|
|
63
70
|
```ruby
|
64
|
-
|
71
|
+
#rails 4
|
72
|
+
gem 'rails_select_on_includes', '~> 0.4.10'
|
73
|
+
|
74
|
+
#rails 5
|
75
|
+
gem 'rails_select_on_includes', '~> 0.5.6'
|
65
76
|
```
|
66
77
|
|
67
78
|
And then execute:
|
@@ -74,31 +85,31 @@ Or install it yourself as:
|
|
74
85
|
|
75
86
|
## Usage
|
76
87
|
|
77
|
-
Works out of the box,
|
78
|
-
since query already contains all columns, i.e. to_sql returns same string.
|
79
|
-
Works with selection in all formats:
|
88
|
+
Works out of the box, monkey-patches base-class alias columns, for select attributes, and JoinBase with JoinDependency to proper typecasting.
|
80
89
|
|
81
|
-
|
90
|
+
It not affecting query creation, since query already contains all columns, i.e. to_sql returns same string.
|
91
|
+
Works with selection in all formats:
|
82
92
|
|
83
|
-
|
93
|
+
1. 'table_name.column' or 'table_name.column as column_1' will be parsed! distinct on can be used also
|
94
|
+
2. '(subquery with AS) AS column_1 '
|
95
|
+
3. Select with aliased arel function: .select(Comment.arel_table[:id].count.as('comments_count'))
|
96
|
+
4. Select with aliased arel attirubte: .select(Comment.arel_table[:column].as('column_alias'))
|
84
97
|
|
85
|
-
3 { table_name: 2 } where 2 relates to upper syntax
|
86
98
|
|
87
99
|
## Usage (рус)
|
88
100
|
|
89
|
-
Работает из коробки, нежно манки-патча алиасы прямо перед инстанцированием коллекции, не влияет на создаваемый запрос в БД т.е to_sql не меняется.
|
101
|
+
Работает из коробки, нежно манки-патча алиасы прямо перед инстанцированием коллекции, а так же не менее нежно JoinBase и JoinDependency :), чтобы полученные аттрибуты были приличных типов, а не только строк, не влияет на создаваемый запрос в БД т.е to_sql не меняется.
|
90
102
|
|
91
103
|
Поддерживает select в следующих форматах :
|
92
104
|
|
93
|
-
1 'table_name.column' or 'table_name.column as column_1'
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
3 { table_name: 2 } where 2 relates to upper syntax
|
105
|
+
1. 'table_name.column' or 'table_name.column as column_1' will be parsed! distinct on can be used also
|
106
|
+
2. '(subquery with AS) AS column_1 '
|
107
|
+
3. Select with aliased arel function: .select(Comment.arel_table[:id].count.as('comments_count'))
|
108
|
+
4. Select with aliased arel attirubte: .select(Comment.arel_table[:column].as('column_alias'))
|
98
109
|
|
99
110
|
## Testing
|
100
111
|
|
101
|
-
|
112
|
+
rake test
|
102
113
|
|
103
114
|
## Contributing
|
104
115
|
|
data/Rakefile
CHANGED
@@ -20,21 +20,21 @@ require 'active_support/core_ext/string/filters'
|
|
20
20
|
@virtual_attributes_names = []
|
21
21
|
end
|
22
22
|
# valid formats are:
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
23
|
+
# 'table_name.column' or 'table_name.column as column_1' will be parsed! distinct on can be used also
|
24
|
+
# '(subquery with AS) AS column_1 '
|
25
|
+
# Select with aliased arel function: .select(Comment.arel_table[:id].count.as('comments_count'))
|
26
|
+
# Select with aliased arel attirubte: .select(Comment.arel_table[:column].as('column_alias'))
|
26
27
|
def update_aliases_to_select_values( select_values )
|
27
28
|
return if select_values.blank?
|
28
29
|
select_values.each do |sv|
|
30
|
+
|
29
31
|
# if sv is symbol that we assume that its a base table column and it will be aliased and added as usual
|
30
32
|
# all we need is some specials joins+select from related tables
|
31
33
|
case sv
|
32
|
-
|
33
|
-
flatten_hash_values(sv).each { |sub_sv| add_virtual_attribute(sub_sv) }
|
34
|
-
when String
|
34
|
+
when String
|
35
35
|
sv.split( ", " ).each do |sub_sv|
|
36
36
|
if sub_sv[/.+ as .+/i]
|
37
|
-
add_virtual_attribute(sub_sv
|
37
|
+
add_virtual_attribute(sub_sv.rpartition(/ as /i).last.strip)
|
38
38
|
elsif sub_sv[/.+\.[^\*]+/]
|
39
39
|
add_virtual_attribute(sub_sv[/\..+/][1..-1].strip)
|
40
40
|
end
|
@@ -32,6 +32,10 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_dependency "activerecord", ">=5"
|
34
34
|
|
35
|
+
spec.add_development_dependency "rails", ">=5"
|
35
36
|
spec.add_development_dependency "bundler", "~> 1.13"
|
36
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency 'sqlite3'
|
39
|
+
|
40
|
+
spec.add_development_dependency 'pry-byebug'
|
37
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_select_on_includes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,34 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
55
97
|
description: Patching rails include/select/virtual attributes issue ( https://github.com/rails/rails/issues/15185
|
56
98
|
)
|
57
99
|
email:
|
@@ -61,12 +103,6 @@ extensions: []
|
|
61
103
|
extra_rdoc_files: []
|
62
104
|
files:
|
63
105
|
- ".gitignore"
|
64
|
-
- ".idea/.name"
|
65
|
-
- ".idea/misc.xml"
|
66
|
-
- ".idea/modules.xml"
|
67
|
-
- ".idea/rails_select_on_includes.iml"
|
68
|
-
- ".idea/vcs.xml"
|
69
|
-
- ".idea/workspace.xml"
|
70
106
|
- Gemfile
|
71
107
|
- LICENSE.txt
|
72
108
|
- README.md
|
@@ -97,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
133
|
version: '0'
|
98
134
|
requirements: []
|
99
135
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.6.11
|
101
137
|
signing_key:
|
102
138
|
specification_version: 4
|
103
139
|
summary: Patching rails include/select/virtual attributes issue
|