active_record_distinct_on 1.8.0 → 1.10.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c41d4a875c89c77cd5cb0770524f165ad432a749ff720b1b69b0b838356ea1f
4
- data.tar.gz: 90c6a266ee1c08811c9d21e889ef054dd87ab9c6784c97c358194498ba4e9672
3
+ metadata.gz: e1b5bbf7361a3887a2377524eb168011972789a31def971cf57c38967aa9113f
4
+ data.tar.gz: 020edb2aa184137c0da2383051084ef14057ebdfa46e8852a4020868b0937f78
5
5
  SHA512:
6
- metadata.gz: f30ccbc69d1ec1e4b57ac5110bf9f58485960713f1a036c275609f1924f043e85ea3d4d364c6c4cbe85b1c2fee2e25109d097a227b6cd8a3ca133dcefa92ca8f
7
- data.tar.gz: 92f71fe2296821363701a129bb7bb4d673ab4f2d35ce4548e41f66b0ef2741dcf49fd14869fcc6c79f85432d46e8607719cb72f57aa36965a293aeecdb1a6e62
6
+ metadata.gz: da6b5256aae9bc3db1b9ee4cdfc9099d433ba79b6c0c48035ebdd6e8da75d53a966f8bb71e0ec420d488a03459ec4358a6374f2b510efcc9233b22a9359002b1
7
+ data.tar.gz: '0546449e8c468ebe624d8a28a67eda373efe43a6f2048ebafee4fe8457503d2877e4ffafce57c04204b48d54b00746720f33f9f0305c1308348629205a6138b8'
@@ -1,5 +1,4 @@
1
1
  require 'active_record_distinct_on'
2
-
3
2
  module ActiveRecordDistinctOn
4
3
  module DistinctOnQueryMethods
5
4
  extend ActiveSupport::Concern
@@ -8,7 +7,11 @@ module ActiveRecordDistinctOn
8
7
 
9
8
  included do
10
9
  self::MULTI_VALUE_METHODS << :distinct_on
11
- self::INVALID_METHODS_FOR_DELETE_ALL << :distinct_on
10
+ if defined?(self::INVALID_METHODS_FOR_UPDATE_AND_DELETE_ALL)
11
+ self::INVALID_METHODS_FOR_UPDATE_AND_DELETE_ALL << :distinct_on
12
+ else
13
+ self::INVALID_METHODS_FOR_DELETE_ALL << :distinct_on
14
+ end
12
15
  self::VALUE_METHODS << :distinct_on
13
16
  self::DEFAULT_VALUES[:distinct_on] = FROZEN_EMPTY_ARRAY if defined?(self::DEFAULT_VALUES)
14
17
  end
@@ -70,15 +73,26 @@ module ActiveRecordDistinctOn
70
73
  end
71
74
 
72
75
  def distinct_on_arel_columns
73
- arel_attributes = distinct_on_values.map { |field|
74
- if klass.attribute_alias?(field)
75
- arel_table[klass.attribute_alias(field).to_sym]
76
+ arel_attributes = distinct_on_values.map do |field|
77
+ if field.is_a?(String)
78
+ field
79
+ elsif field.is_a?(Hash)
80
+ assoc = field.keys.first
81
+ assoc_klass = klass.reflect_on_association(assoc).klass
82
+ assoc_field = field[assoc].to_sym
83
+ build_distinct_on_field(assoc_klass, assoc_field)
76
84
  else
77
- arel_table[field]
85
+ build_distinct_on_field(klass, field)
78
86
  end
79
- }
87
+ end
88
+
89
+ arel_columns(arel_attributes)
90
+ end
91
+
92
+ def build_distinct_on_field(klass, field)
93
+ return klass.arel_table[klass.attribute_alias(field).to_sym] if klass.attribute_alias?(field)
80
94
 
81
- arel_columns arel_attributes
95
+ klass.arel_table[field]
82
96
  end
83
97
  end
84
98
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordDistinctOn
2
- VERSION = '1.8.0'
2
+ VERSION = '1.10.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_distinct_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alec Larsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-14 00:00:00.000000000 Z
11
+ date: 2025-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord