baby_squeel 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +76 -11
- data/README.md +1 -1
- data/baby_squeel.gemspec +2 -2
- data/lib/baby_squeel/active_record/query_methods.rb +43 -6
- data/lib/baby_squeel/active_record/version_helper.rb +21 -0
- data/lib/baby_squeel/association.rb +8 -2
- data/lib/baby_squeel/calculation.rb +11 -7
- data/lib/baby_squeel/join_dependency.rb +57 -17
- data/lib/baby_squeel/version.rb +1 -1
- metadata +16 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 154cc7b5379993dfa67f76c182bfe810f5c9b941930ec69e386270e5751201da
|
4
|
+
data.tar.gz: 873324d4d500c03621c6a3fb20321a948f2b9ae9dadf098aff028b154dc57f36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29e8eb5d1225e3e8f00908af60da6b5deeebeb49467a52aa875fcad70972002d312dac0151be4d4ca7562012cc7c21593c630f1b44b2f20733cb43bdc997854
|
7
|
+
data.tar.gz: 3b3b9957bc49729ffdcf5bda14ef4446816cf8cbd12facf67a30ec8912bbb260e0a0543334a3e840a0d691ee8d990754dbe23e687129321b88a46360b2d60e76
|
data/CHANGELOG.md
CHANGED
@@ -1,149 +1,212 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.4.2] - 2022-01-24
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
|
7
|
+
- Added support for activerecord 7.0 (#116)
|
8
|
+
- Added support for activerecord 6.1 (#116)
|
9
|
+
- Added support for activerecord 6.0 (#116)
|
10
|
+
|
3
11
|
## [1.4.1] - 2021-06-17
|
4
|
-
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
5
15
|
- Fixed a bug related to checking the Active Record version.
|
6
16
|
|
7
17
|
## [1.4.0] - 2021-06-17
|
8
|
-
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
9
21
|
- Fix table alias when joining a polymorphic table twice (#108)
|
10
22
|
- Removed internal class `BabySqueel::Pluck`. You can still use `plucking`. For example, `Post.joining { author }.plucking { author.name }`
|
11
23
|
- Removed old code from Active Record < 5.2
|
12
24
|
- Removed dependency `join_dependency`
|
13
25
|
|
14
26
|
## [1.4.0.beta1] - 2021-04-21
|
15
|
-
|
27
|
+
|
28
|
+
### Fixed
|
29
|
+
|
16
30
|
- Add Support for activerecord '>= 5.2.3'
|
17
31
|
- Drop Support for Active Record versions that have reached EOL (activerecord < 5.2)
|
18
32
|
- Use polyamorous from ransack '~> 2.3'
|
19
33
|
|
20
34
|
## [1.3.1] - 2018-05-15
|
21
|
-
|
35
|
+
|
36
|
+
### Fixed
|
37
|
+
|
22
38
|
- Upgraded `join_dependency` requirement, which fixes [issue #1](https://github.com/rzane/join_dependency/issues/1).
|
23
39
|
|
24
40
|
## [1.3.0] - 2018-05-04
|
25
|
-
|
41
|
+
|
42
|
+
### Added
|
43
|
+
|
26
44
|
- The ability to use `plucking` with an array of nodes. For example, `User.plucking { [id, name] }`.
|
27
45
|
|
28
46
|
## [1.2.1] - 2018-04-25
|
29
|
-
|
47
|
+
|
48
|
+
### Fixed
|
49
|
+
|
30
50
|
- Added support for Active Record 5.2
|
31
51
|
|
32
52
|
## [1.2.0] - 2017-10-20
|
53
|
+
|
33
54
|
### Added
|
55
|
+
|
34
56
|
- `reordering`, which is just a BabySqueel version of Active Record's `reorder`.
|
35
57
|
- `on` expressions can now be given a block that will yield the current node (#77).
|
36
58
|
|
37
59
|
## [1.1.5] - 2017-05-26
|
60
|
+
|
38
61
|
### Fixed
|
62
|
+
|
39
63
|
- Returning an empty hash from a `where.has {}` block would generate invalid SQL (#69).
|
40
64
|
|
41
65
|
## [1.1.4] - 2017-04-13
|
66
|
+
|
42
67
|
### Fixed
|
68
|
+
|
43
69
|
- Nodes::Attribute#in and #not_in generate valid SQL when given ActiveRecord::NullRelations.
|
44
70
|
|
45
71
|
## [1.1.3] - 2017-03-31
|
72
|
+
|
46
73
|
### Fixed
|
74
|
+
|
47
75
|
- Nodes::Attribute#in was not returning BabySqueel node. As a result, you couldn't chain on it. This fixes #61.
|
48
76
|
|
49
77
|
## [1.1.2] - 2017-03-21
|
78
|
+
|
50
79
|
### Fixed
|
80
|
+
|
51
81
|
- Check if a reflection has a parent reflection before comparing them. This fixes #56.
|
52
82
|
|
53
83
|
### Refactored
|
84
|
+
|
54
85
|
- The logic encapsulated in `#method_missing` and `#respond_to_missing?` was difficult to follow, because it was falling back to `super`, sometimes going up the inheritance tree multiple levels. The addition of `BabySqueel::Resolver` now handles this a little more gracefully.
|
55
86
|
|
56
87
|
## [1.1.1] - 2017-02-14
|
88
|
+
|
57
89
|
### Fixed
|
90
|
+
|
58
91
|
- There is a bug in Active Record where the `AliasTracker` initializes `Arel::Table`s use the wrong `type_caster`. To address this, BabySqueel must re-initialize the `Arel::Table` with the correct `type_caster` (#54).
|
59
92
|
|
60
93
|
## [1.1.0] - 2017-02-10
|
94
|
+
|
61
95
|
> This version drops support for Active Record 4.1. If you're stil on 4.1, you should seriously consider upgrading to at least 4.2.
|
62
96
|
|
63
97
|
### Added
|
98
|
+
|
64
99
|
- DSLs for ActiveRecord::Relation::Calculations. You can now use `plucking`, `counting`, `summing`, `averaging`, `minimizing`, and `maximizing`.
|
65
100
|
|
66
101
|
## [1.0.3] - 2017-02-09
|
102
|
+
|
67
103
|
### Added
|
104
|
+
|
68
105
|
- Support for `pluck`.
|
69
106
|
- Support for `not_in`.
|
70
107
|
|
71
108
|
## [1.0.2] - 2017-02-07
|
109
|
+
|
72
110
|
### Added
|
111
|
+
|
73
112
|
- `BabySqueel::Association` now has `#==` and `#!=`. This is only supported for Rails 5+. Example: `Post.where { author: Author.last }`.
|
74
113
|
|
75
114
|
### Fixed
|
115
|
+
|
76
116
|
- Incorrect alias detection caused by not tracking the full path to a join (#37).
|
77
117
|
|
78
118
|
## [1.0.1] - 2016-11-07
|
119
|
+
|
79
120
|
### Added
|
80
|
-
|
121
|
+
|
122
|
+
- Add DSL#\_ for wrapping expressions in Arel::Node::Grouping. Thanks to [@odedniv].
|
81
123
|
|
82
124
|
### Fixed
|
125
|
+
|
83
126
|
- Use strings for attribute names like Rails does. Symbols were preventing things like `unscope` from working. Thanks to [@chewi].
|
84
127
|
- `where.has {}` will now accept `nil`.
|
85
128
|
- Arel::Nodes::Function did not previously include Arel::Math, so now you can do math operations on the result of SQL functions.
|
86
129
|
- Arel::Nodes::Binary did not previously include Arel::AliasPredication. Binary nodes can now be aliased using `as`.
|
87
130
|
|
88
131
|
## [1.0.0] - 2016-09-09
|
132
|
+
|
89
133
|
### Added
|
90
|
-
|
134
|
+
|
135
|
+
- Polyamorous. Unfortunately, this _does_ monkey-patch Active Record internals, but there just isn't any other reliable way to generate outer joins. Baby Squeel, itself, will still keep monkey patching to an absolute minimum.
|
91
136
|
- Within DSL blocks, you can use `exists` and `not_exists` with Active Record relations. For example: `Post.where.has { exists Post.where(title: 'Fun') }`.`
|
92
137
|
- Support for polymorphic associations.
|
93
138
|
|
94
139
|
### Deprecations
|
140
|
+
|
95
141
|
- Removed support for Active Record 4.0.x
|
96
142
|
|
97
143
|
### Changed
|
144
|
+
|
98
145
|
- BabySqueel::JoinDependency is no longer a class responsible for creating Arel joins. It is now a namespace for utilities used when working with the ActiveRecord::Association::JoinDependency class.
|
99
146
|
- BabySqueel::Nodes::Generic is now BabySqueel::Nodes::Node.
|
100
147
|
- Arel nodes are only extended with the behaviors they need. Previously, all Arel nodes were being extended with `Arel::AliasPredication`, `Arel::OrderPredications`, and `Arel::Math`.
|
101
148
|
|
102
149
|
### Fixed
|
150
|
+
|
103
151
|
- Fixed deprecation warnings on Active Record 5 when initializing an Arel::Table without a type caster.
|
104
152
|
- No more duplicate joins. Previously, Baby Squeel did a very poor job of ensuring that you didn't join an association twice.
|
105
|
-
- Alias detection should now
|
153
|
+
- Alias detection should now _actually_ work. The previous implementation was naive.
|
106
154
|
|
107
155
|
## [0.3.1] - 2016-08-02
|
156
|
+
|
108
157
|
### Added
|
158
|
+
|
109
159
|
- Ported backticks and #my from Squeel
|
110
160
|
|
111
161
|
### Changed
|
162
|
+
|
112
163
|
- DSL#sql now returns a node wrapped in a BabySqueel proxy.
|
113
164
|
|
114
165
|
## [0.3.0] - 2016-06-26
|
166
|
+
|
115
167
|
### Added
|
168
|
+
|
116
169
|
- Added Squeel compatibility mode that allows `select`, `order`, `joins`, `group`, `where`, and `having` to accept DSL blocks.
|
117
170
|
- Added the ability to query tables that aren't backed by Active Record models.
|
118
171
|
- Added `BabySqueel::[]`, which provides a `BabySqueel::Relation` for models, or a `BabySqueel::Table` for symbols/strings.
|
119
172
|
|
120
173
|
### Changed
|
174
|
+
|
121
175
|
- Renamed `BabySqueel::Association::AliasingError` to `BabySqueel::AssociationAliasingError`.
|
122
176
|
|
123
177
|
## [0.2.2] - 2016-03-30
|
178
|
+
|
124
179
|
### Added
|
180
|
+
|
125
181
|
- Support for `group` (`grouping`) and `having` (`when_having`).
|
126
182
|
- Support for sifters.
|
127
183
|
- Added `quoted` and `sql` helpers for quoting strings and SQL literals.
|
128
184
|
- More descriptive error messages when a column or association is not found.
|
129
185
|
|
130
186
|
### Fixed
|
187
|
+
|
131
188
|
- `Arel::Nodes::Grouping` does not include `Arel::Math`, so operations like `(id + 5) + 3` would fail unexpectedly.
|
132
189
|
- Fix missing bind values When joining through associations with default scope.
|
133
190
|
- Removed `ActiveRecord::VERSION` specific handling of the `WhereChain`.
|
134
191
|
|
135
192
|
## [0.2.1] - 2016-03-27
|
193
|
+
|
136
194
|
### Added
|
195
|
+
|
137
196
|
- Support for subqueries.
|
138
197
|
|
139
198
|
### Fixed
|
199
|
+
|
140
200
|
- Some Arel nodes did not have access to `as` expressions.
|
141
201
|
|
142
202
|
## [0.2.0] - 2016-03-25
|
203
|
+
|
143
204
|
### Added
|
205
|
+
|
144
206
|
- References to aliased joins in a `select`, `where`, or `order` expression now use the aliased table name.
|
145
207
|
|
146
208
|
### Changed
|
209
|
+
|
147
210
|
- Rely on `ActiveRecord::Relation#join_sources` for the implicit construction of join nodes, rather than using the `ActiveRecord::Associations::JoinDependency` directly.
|
148
211
|
|
149
212
|
### Fixed
|
@@ -151,10 +214,13 @@
|
|
151
214
|
- Associations referencing the same table weren't being aliased.
|
152
215
|
|
153
216
|
## [0.1.0] - 2016-03-16
|
217
|
+
|
154
218
|
### Added
|
219
|
+
|
155
220
|
- Initial support for selects, orders, wheres, and joins.
|
156
221
|
|
157
|
-
[
|
222
|
+
[unreleased]: https://github.com/rzane/baby_squeel/compare/v1.4.2...HEAD
|
223
|
+
[1.4.2]: https://github.com/rzane/baby_squeel/compare/v1.4.1...v1.4.2
|
158
224
|
[1.4.1]: https://github.com/rzane/baby_squeel/compare/v1.4.0...v1.4.1
|
159
225
|
[1.4.0]: https://github.com/rzane/baby_squeel/compare/v1.4.0.beta1...v1.4.0
|
160
226
|
[1.4.0.beta1]: https://github.com/rzane/baby_squeel/compare/v1.3.1...v1.4.0.beta1
|
@@ -177,6 +243,5 @@
|
|
177
243
|
[0.2.2]: https://github.com/rzane/baby_squeel/compare/v0.2.1...v0.2.2
|
178
244
|
[0.2.1]: https://github.com/rzane/baby_squeel/compare/v0.2.0...v0.2.1
|
179
245
|
[0.2.0]: https://github.com/rzane/baby_squeel/compare/v0.1.0...v0.2.0
|
180
|
-
|
181
246
|
[@chewi]: https://github.com/chewi
|
182
247
|
[@odedniv]: https://github.com/odedniv
|
data/README.md
CHANGED
@@ -329,7 +329,7 @@ Check out the [migration guide](https://github.com/rzane/baby_squeel/wiki/Migrat
|
|
329
329
|
|
330
330
|
## Development
|
331
331
|
|
332
|
-
1. Pick an Active Record version to develop against, then export it: `export AR=
|
332
|
+
1. Pick an Active Record version to develop against, then export it: `export AR=6.1.4`.
|
333
333
|
2. Run `bin/setup` to install dependencies.
|
334
334
|
3. Run `rake` to run the specs.
|
335
335
|
|
data/baby_squeel.gemspec
CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.files = Dir.glob('{lib/**/*,*.{md,txt,gemspec}}')
|
21
21
|
|
22
|
-
spec.add_dependency 'activerecord', '
|
22
|
+
spec.add_dependency 'activerecord', '>= 5.2', '< 7.1'
|
23
23
|
spec.add_dependency 'ransack', '~> 2.3'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 2'
|
26
26
|
spec.add_development_dependency 'rake', '~> 13.0'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.10'
|
28
|
-
spec.add_development_dependency 'sqlite3'
|
28
|
+
spec.add_development_dependency 'sqlite3'
|
29
29
|
end
|
@@ -1,9 +1,26 @@
|
|
1
1
|
require 'baby_squeel/dsl'
|
2
2
|
require 'baby_squeel/join_dependency'
|
3
|
+
require 'baby_squeel/active_record/version_helper'
|
3
4
|
|
4
5
|
module BabySqueel
|
5
6
|
module ActiveRecord
|
6
7
|
module QueryMethods
|
8
|
+
# This class allows BabySqueel to slip custom
|
9
|
+
# joins_values into Active Record's JoinDependency
|
10
|
+
module Injector6_1
|
11
|
+
def each(&block)
|
12
|
+
super do |join|
|
13
|
+
if join.is_a?(BabySqueel::Join)
|
14
|
+
result = block.binding.local_variables.include?(:result) && block.binding.local_variable_get(:result)
|
15
|
+
result << join if result
|
16
|
+
join
|
17
|
+
else
|
18
|
+
block.call(join)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
7
24
|
# Constructs Arel for ActiveRecord::QueryMethods#joins using the DSL.
|
8
25
|
def joining(&block)
|
9
26
|
joins DSL.evaluate(self, &block)
|
@@ -36,12 +53,32 @@ module BabySqueel
|
|
36
53
|
|
37
54
|
private
|
38
55
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
56
|
+
if BabySqueel::ActiveRecord::VersionHelper.at_least_6_1?
|
57
|
+
# https://github.com/rails/rails/commit/c0c53ee9d28134757cf1418521cb97c4a135f140
|
58
|
+
def select_association_list(*args)
|
59
|
+
args[0].extend(BabySqueel::ActiveRecord::QueryMethods::Injector6_1)
|
60
|
+
super *args
|
61
|
+
end
|
62
|
+
|
63
|
+
def construct_join_dependency(associations, join_type)
|
64
|
+
super(associations, join_type).extend(BabySqueel::JoinDependency::Injector6_1)
|
65
|
+
end
|
66
|
+
elsif BabySqueel::ActiveRecord::VersionHelper.at_least_6_0?
|
67
|
+
# Active Record will call `each` on the `joins`. The
|
68
|
+
# Injector has a custom `each` method that handles
|
69
|
+
# BabySqueel::Join nodes.
|
70
|
+
def build_joins(*args)
|
71
|
+
args[1] = BabySqueel::JoinDependency::Injector6_0.new(args.second)
|
72
|
+
super(*args)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
# Active Record will call `group_by` on the `joins`. The
|
76
|
+
# Injector has a custom `group_by` method that handles
|
77
|
+
# BabySqueel::Join nodes.
|
78
|
+
def build_joins(*args)
|
79
|
+
args[1] = BabySqueel::JoinDependency::Injector5_2.new(args.second)
|
80
|
+
super(*args)
|
81
|
+
end
|
45
82
|
end
|
46
83
|
end
|
47
84
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'baby_squeel/dsl'
|
2
|
+
|
3
|
+
module BabySqueel
|
4
|
+
module ActiveRecord
|
5
|
+
class VersionHelper
|
6
|
+
def self.at_least_6_1?
|
7
|
+
::ActiveRecord::VERSION::MAJOR > 6 ||
|
8
|
+
::ActiveRecord::VERSION::MAJOR == 6 && ::ActiveRecord::VERSION::MINOR >= 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.at_least_6_0?
|
12
|
+
::ActiveRecord::VERSION::MAJOR >= 6
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.at_least_5_2_3?
|
16
|
+
at_least_6_0? ||
|
17
|
+
::ActiveRecord::VERSION::MAJOR >= 5 && ::ActiveRecord::VERSION::MINOR >= 2 && ::ActiveRecord::VERSION::TINY >= 3
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'baby_squeel/relation'
|
2
|
+
require 'baby_squeel/active_record/version_helper'
|
2
3
|
|
3
4
|
module BabySqueel
|
4
5
|
class Association < Relation
|
@@ -99,8 +100,13 @@ module BabySqueel
|
|
99
100
|
def build_where_clause(other)
|
100
101
|
if valid_where_clause?(other)
|
101
102
|
relation = @parent._scope.all
|
102
|
-
|
103
|
-
|
103
|
+
|
104
|
+
if BabySqueel::ActiveRecord::VersionHelper.at_least_6_1?
|
105
|
+
relation.send(:build_where_clause, { _reflection.name => other }, [])
|
106
|
+
else
|
107
|
+
factory = relation.send(:where_clause_factory)
|
108
|
+
factory.build({ _reflection.name => other }, [])
|
109
|
+
end
|
104
110
|
else
|
105
111
|
raise AssociationComparisonError.new(_reflection.name, other)
|
106
112
|
end
|
@@ -15,15 +15,19 @@ module BabySqueel
|
|
15
15
|
# caching because the alias would have a unique name every
|
16
16
|
# time.
|
17
17
|
def to_s
|
18
|
-
|
19
|
-
|
20
|
-
child.
|
21
|
-
|
22
|
-
child.name
|
18
|
+
if node.respond_to?(:map)
|
19
|
+
names = node.map do |child|
|
20
|
+
if child.kind_of?(String) || child.kind_of?(Symbol)
|
21
|
+
child.to_s
|
22
|
+
elsif child.respond_to?(:name)
|
23
|
+
child.name.to_s
|
24
|
+
end
|
23
25
|
end
|
26
|
+
names.compact.uniq.join('_')
|
27
|
+
else
|
28
|
+
# fix for https://github.com/rails/rails/commit/fc38ff6e4417295c870f419f7c164ab5a7dbc4a5
|
29
|
+
node.to_sql.split('"').map { |v| v.tr('^A-Za-z0-9_', '').presence }.compact.uniq.join('_')
|
24
30
|
end
|
25
|
-
|
26
|
-
names.compact.uniq.join('_')
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'baby_squeel/active_record/version_helper'
|
2
|
+
|
1
3
|
module BabySqueel
|
2
4
|
module JoinDependency
|
3
5
|
# This class allows BabySqueel to slip custom
|
4
6
|
# joins_values into Active Record's JoinDependency
|
5
|
-
class
|
7
|
+
class Injector5_2 < Array # :nodoc:
|
6
8
|
# Active Record will call group_by on this object
|
7
9
|
# in ActiveRecord::QueryMethods#build_joins. This
|
8
10
|
# allows BabySqueel::Joins to be treated
|
@@ -20,6 +22,39 @@ module BabySqueel
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
25
|
+
# This class allows BabySqueel to slip custom
|
26
|
+
# joins_values into Active Record's JoinDependency
|
27
|
+
class Injector6_0 < Array # :nodoc:
|
28
|
+
# https://github.com/rails/rails/pull/36805/files
|
29
|
+
# This commit changed group_by to each
|
30
|
+
def each(&block)
|
31
|
+
super do |join|
|
32
|
+
if block.binding.local_variables.include?(:buckets)
|
33
|
+
buckets = block.binding.local_variable_get(:buckets)
|
34
|
+
|
35
|
+
case join
|
36
|
+
when BabySqueel::Join
|
37
|
+
buckets[:association_join] << join
|
38
|
+
else
|
39
|
+
block.call(join)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
block.call(join)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# This is a 'fix' for the left outer joins
|
49
|
+
# rails way would be to call left_outer_joins so the join_type gets set to Arel::Nodes::OuterJoin
|
50
|
+
# Maybe this could be fixed in joining but I do not know how.
|
51
|
+
module Injector6_1 # :nodoc:
|
52
|
+
def make_constraints(parent, child, join_type) # :nodoc:
|
53
|
+
join_type = child.join_type if child.join_type
|
54
|
+
super(parent, child, join_type)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
23
58
|
class Builder # :nodoc:
|
24
59
|
attr_reader :join_dependency
|
25
60
|
|
@@ -31,10 +66,19 @@ module BabySqueel
|
|
31
66
|
# a list (in order of chaining) of associations and finding
|
32
67
|
# the respective JoinAssociation at each level.
|
33
68
|
def find_alias(associations)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
69
|
+
if BabySqueel::ActiveRecord::VersionHelper.at_least_6_1?
|
70
|
+
# construct_tables! got removed by rails
|
71
|
+
# https://github.com/rails/rails/commit/590b045ee2c0906ff162e6658a184afb201865d7
|
72
|
+
#
|
73
|
+
# construct_tables_for_association! is a method from the polyamorous (ransack) gem
|
74
|
+
join_root = join_dependency.send(:join_root)
|
75
|
+
join_root.each_children do |parent, child|
|
76
|
+
join_dependency.construct_tables_for_association!(parent, child)
|
77
|
+
end
|
78
|
+
elsif BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
|
79
|
+
# If we tell join_dependency to construct its tables, Active Record
|
80
|
+
# handles building the correct aliases and attaching them to its
|
81
|
+
# JoinDepenencies.
|
38
82
|
join_dependency.send(:construct_tables!, join_dependency.send(:join_root))
|
39
83
|
end
|
40
84
|
|
@@ -69,7 +113,7 @@ module BabySqueel
|
|
69
113
|
def collect_joins(relation)
|
70
114
|
joins = []
|
71
115
|
joins += relation.joins_values
|
72
|
-
joins += relation.left_outer_joins_values
|
116
|
+
joins += relation.left_outer_joins_values
|
73
117
|
|
74
118
|
buckets = joins.group_by do |join|
|
75
119
|
case join
|
@@ -103,11 +147,15 @@ module BabySqueel
|
|
103
147
|
join_list = join_nodes + joins
|
104
148
|
|
105
149
|
alias_tracker = Associations::AliasTracker.create(relation.klass.connection, relation.table.name, join_list)
|
106
|
-
if
|
107
|
-
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins,
|
108
|
-
|
150
|
+
if BabySqueel::ActiveRecord::VersionHelper.at_least_6_0?
|
151
|
+
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::InnerJoin)
|
152
|
+
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
|
153
|
+
elsif BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
|
109
154
|
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins)
|
110
155
|
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
|
156
|
+
else
|
157
|
+
# Rails 5.2.0 - 5.2.2
|
158
|
+
join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
|
111
159
|
end
|
112
160
|
join_nodes.each do |join|
|
113
161
|
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
@@ -115,14 +163,6 @@ module BabySqueel
|
|
115
163
|
|
116
164
|
join_dependency
|
117
165
|
end
|
118
|
-
|
119
|
-
def exactly?(version)
|
120
|
-
::ActiveRecord.gem_version == Gem::Version.new(version)
|
121
|
-
end
|
122
|
-
|
123
|
-
def at_least?(version)
|
124
|
-
::ActiveRecord.gem_version >= Gem::Version.new(version)
|
125
|
-
end
|
126
166
|
end
|
127
167
|
end
|
128
168
|
end
|
data/lib/baby_squeel/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baby_squeel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Zane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '5.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: ransack
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +90,16 @@ dependencies:
|
|
84
90
|
name: sqlite3
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- - "
|
93
|
+
- - ">="
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
95
|
+
version: '0'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- - "
|
100
|
+
- - ">="
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
102
|
+
version: '0'
|
97
103
|
description: An expressive query DSL for Active Record 4 and 5.
|
98
104
|
email:
|
99
105
|
- ray@promptworks.com
|
@@ -110,6 +116,7 @@ files:
|
|
110
116
|
- lib/baby_squeel/active_record/base.rb
|
111
117
|
- lib/baby_squeel/active_record/calculations.rb
|
112
118
|
- lib/baby_squeel/active_record/query_methods.rb
|
119
|
+
- lib/baby_squeel/active_record/version_helper.rb
|
113
120
|
- lib/baby_squeel/active_record/where_chain.rb
|
114
121
|
- lib/baby_squeel/association.rb
|
115
122
|
- lib/baby_squeel/calculation.rb
|
@@ -149,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
156
|
- !ruby/object:Gem::Version
|
150
157
|
version: '0'
|
151
158
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
159
|
+
rubygems_version: 3.2.22
|
153
160
|
signing_key:
|
154
161
|
specification_version: 4
|
155
162
|
summary: An expressive query DSL for Active Record 4 and 5.
|