left_joins 1.0.3 → 1.0.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
- SHA1:
3
- metadata.gz: 33da27b6e6da1cea9aed88c993c7ab327f831331
4
- data.tar.gz: dc0cf372cf8c4fb4d551e8710ad99ade145faae1
2
+ SHA256:
3
+ metadata.gz: df7ca5a2313f0d5b956fa812dcf528646ffd79b60d28421d6abfd9cebafdb891
4
+ data.tar.gz: 48265e1cd3b79d43e0c399fe6a1420126fe14d71b0f7a028344e6d739fc53e6c
5
5
  SHA512:
6
- metadata.gz: 5814d112df40ef96bface633fa7493cc69144eb6830a4c1d26be820a318abed1bbadfe216d2b2fbd3328cf42eac9a15e3e3e8013c7ebbb42577b36206a3f84b9
7
- data.tar.gz: 809e8b6174b80093671bd7cdee59e996423a229777968da0711cddfd7d5b1f55008dd5b1fe4d8bfdbd1cb4c93bdc850d7295779ca527154bc41dbec8a8919a9e
6
+ metadata.gz: 7b81a965effac0c35447cbc05e4a28e9ba70a4db17899516e15af7933d8565e02f082a1dd59c7f44165127c176b33fed08866576b48d09b638fb1c82fa530984
7
+ data.tar.gz: 9b1a1901c4c9e2b8b79698932394801e42de7839950140c36d0c684ab77967313684561d7db87f7ec65d330bedc63d32432d2b8f60de05c108dbb720ecafa248
@@ -1,10 +1,13 @@
1
1
  ## Change Log
2
2
 
3
- ### v1.0.2 2018/01/12
3
+ ### [v1.0.3](https://github.com/khiav223577/left_joins/compare/v1.0.2...v1.0.3) 2018/06/30
4
+ - [#5](https://github.com/khiav223577/left_joins/pull/5) Fix: JoinDependency#make_constraints is not defined in Rails 4.0 (@khiav223577)
5
+
6
+ ### [v1.0.2](https://github.com/khiav223577/left_joins/compare/v1.0.1...v1.0.2) 2018/01/12
4
7
  - [#3](https://github.com/khiav223577/left_joins/pull/3) fix missing left joins when using in association condition (@khiav223577)
5
8
 
6
- ### v1.0.1 2017/12/25
9
+ ### [v1.0.1](https://github.com/khiav223577/left_joins/compare/v1.0.0...v1.0.1) 2017/12/25
7
10
  - [#2](https://github.com/khiav223577/left_joins/pull/2) Fix count which would sometimes force a DISTINCT (@khiav223577)
8
11
 
9
12
  ### v1.0.0 2017/12/25
10
- - [#1](https://github.com/khiav223577/left_joins/pull/1) implement left joins (@khiav223577)
13
+ - [#1](https://github.com/khiav223577/left_joins/pull/1) implement left joins (@khiav223577)
@@ -18,6 +18,7 @@ module ActiveRecord::QueryMethods
18
18
 
19
19
  args.compact!
20
20
  args.flatten!
21
+ self.distinct_value = false
21
22
 
22
23
  return (LeftJoins::IS_RAILS3_FLAG ? clone : spawn).left_outer_joins!(*args)
23
24
  end
@@ -39,10 +40,10 @@ module ActiveRecord::QueryMethods
39
40
  end
40
41
 
41
42
  alias_method :build_joins_without_join_type, :build_joins
42
- def build_joins(manager, joins, join_type = Arel::Nodes::InnerJoin)
43
- Thread.current.thread_variable_set :left_joins_join_type, join_type
43
+ def build_joins(manager, joins, join_type = nil)
44
+ Thread.current.thread_variable_set(:left_joins_join_type, join_type)
44
45
  result = build_joins_without_join_type(manager, joins)
45
- Thread.current.thread_variable_set :left_joins_join_type, nil
46
+ Thread.current.thread_variable_set(:left_joins_join_type, nil)
46
47
  return result
47
48
  end
48
49
 
@@ -62,28 +63,36 @@ module ActiveRecord::QueryMethods
62
63
  if private_method_defined?(:make_constraints)
63
64
  alias_method :make_constraints_without_hooking_join_type, :make_constraints
64
65
  def make_constraints(*args, join_type)
65
- join_type = Thread.current.thread_variable_get :left_joins_join_type || join_type
66
+ join_type = Thread.current.thread_variable_get(:left_joins_join_type) || join_type
66
67
  return make_constraints_without_hooking_join_type(*args, join_type)
67
68
  end
68
69
  else
69
70
  alias_method :build_without_hooking_join_type, :build
70
71
  def build(associations, parent = nil, join_type = Arel::Nodes::InnerJoin)
71
- join_type = Thread.current.thread_variable_get :left_joins_join_type || join_type
72
+ join_type = Thread.current.thread_variable_get(:left_joins_join_type) || join_type
72
73
  return build_without_hooking_join_type(associations, parent, join_type)
73
74
  end
74
75
  end
75
76
  end
76
77
 
77
78
  module ActiveRecord::Calculations
79
+ # This method is copied from activerecord-4.2.10/lib/active_record/relation/calculations.rb
80
+ # and modified this line `distinct = true` to `distinct = true if distinct == nil`
78
81
  def perform_calculation(operation, column_name, options = {})
82
+ # TODO: Remove options argument as soon we remove support to
83
+ # activerecord-deprecated_finders.
79
84
  operation = operation.to_s.downcase
80
85
 
81
- # If #count is used with #distinct (i.e. `relation.distinct.count`) it is
82
- # considered distinct.
86
+ # If #count is used with #distinct / #uniq it is considered distinct. (eg. relation.distinct.count)
83
87
  distinct = options[:distinct] || self.distinct_value
84
88
 
85
89
  if operation == "count"
86
- column_name ||= select_for_count
90
+ column_name ||= (select_for_count || :all)
91
+
92
+ unless arel.ast.grep(Arel::Nodes::OuterJoin).empty?
93
+ distinct = true if distinct == nil
94
+ end
95
+
87
96
  column_name = primary_key if column_name == :all && distinct
88
97
  distinct = nil if column_name =~ /\s*DISTINCT[\s(]+/i
89
98
  end
@@ -1,3 +1,3 @@
1
1
  module LeftJoins
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -13,4 +13,8 @@ module ActiveRecord::Calculations
13
13
  def distinct_value
14
14
  uniq_value
15
15
  end
16
+
17
+ def distinct_value=(v)
18
+ self.uniq_value = v
19
+ end
16
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: left_joins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.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: 2018-06-30 00:00:00.000000000 Z
11
+ date: 2018-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  requirements: []
143
143
  rubyforge_project:
144
- rubygems_version: 2.6.13
144
+ rubygems_version: 2.7.6
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Backport `left_joins` from Rails 5 for Rails 3 and 4.