active_scaffold 4.2.1 → 4.2.2

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: 0ce255799e0bff6d3854d55afdf9278d3a283f68f6d0b1a639acf5bd229b359a
4
- data.tar.gz: 62761ad0b3530526880f7d8ac464f1f61623f76a6cbdd55512ab6e6102b6f963
3
+ metadata.gz: a411ae5638102ae3b9052929c30afcb44f769c9eeb528fdddd995ba7407bc5b9
4
+ data.tar.gz: 0171ab0f4fbde3b09cffae2553d7a7d90248bb5529f548e2321acb525610edd2
5
5
  SHA512:
6
- metadata.gz: ad75a5aef07ab0ed9a6997847249ebfd30b749ffe6502472a74066e86ff08fd196b85579bdec112108a71d149f7918af79cfeec64cdee23d095440594a33dba0
7
- data.tar.gz: 6bcb9392ee5554b46ebb708d957b061c890b23fc613298c8296370276480b27bae10c4dc7fbb683aeed615aec9bbb1c83de7ac11ada6e1714fcf1d5b6958813b
6
+ metadata.gz: d39d363d9ff5a27b07c124bf7718962d5355c879a77e48f5085f195d739b821276fdbda602078a0995c5385290dd158b2604acf75b863d323ce6ca1ac45d108d
7
+ data.tar.gz: 6afacdeacd3fd4b13d0115a8a7c3faba454c2e755bdea68485ebbbdb2c7a305b7022ca833e8960aa4c5df3258ce72236b5959c450d51306049ab652365429a6c
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ - Support setting form_ui_options with nil, for subforms
2
+ - Support saving when embedded on through singular association, as it's supported for nested too
3
+
1
4
  = 4.2.1
2
5
  - Fix replacing tinymce fields with update_columns
3
6
  - Support refresh_link in radio form UI
@@ -146,6 +146,16 @@ module ActiveScaffold::Actions
146
146
  "#{params[:parent_controller].camelize}Controller"
147
147
  end
148
148
 
149
+ def create_on_through_singular(record, association, parent_record)
150
+ through = parent_record.send(association.through_reflection.name) ||
151
+ parent_record.send(:"build_#{association.through_reflection.name}")
152
+ if association.source_reflection.reverse_association.collection?
153
+ record.send(association.source_reflection.reverse) << through
154
+ else
155
+ record.send(:"#{association.source_reflection.reverse}=", through)
156
+ end
157
+ end
158
+
149
159
  def setup_parent
150
160
  cfg = main_form_controller.active_scaffold_config
151
161
  parent = cfg.model.new
@@ -107,13 +107,7 @@ module ActiveScaffold::Actions
107
107
  if nested.child_association&.singular?
108
108
  record.send(:"#{nested.child_association.name}=", nested_parent_record)
109
109
  elsif nested.create_through_singular?
110
- through = nested_parent_record.send(nested.association.through_reflection.name) ||
111
- nested_parent_record.send(:"build_#{nested.association.through_reflection.name}")
112
- if nested.source_reflection.reverse_association.collection?
113
- record.send(nested.source_reflection.reverse) << through
114
- else
115
- record.send(:"#{nested.source_reflection.reverse}=", through)
116
- end
110
+ create_on_through_singular(record, nested.association, nested_parent_record)
117
111
  else
118
112
  record.send(nested.child_association.name) << nested_parent_record
119
113
  end
@@ -171,7 +171,9 @@ module ActiveScaffold
171
171
  constraints.each do |k, v|
172
172
  column = config.columns[k]
173
173
  if column&.association
174
- if column.association.collection?
174
+ if column.association.through_singular? && column.association.source_reflection.reverse
175
+ create_on_through_singular(record, column.association, column.association.klass.find(v))
176
+ elsif column.association.collection?
175
177
  record.send(k.to_s).send(:<<, column.association.klass.find(v)) unless column.association.nested?
176
178
  elsif column.association.polymorphic?
177
179
  unless v.is_a?(Array) && v.size >= 2
@@ -183,7 +185,7 @@ module ActiveScaffold
183
185
  else
184
186
  record.send(:"#{column.association.foreign_type}=", v[0])
185
187
  end
186
- elsif !column.association.source_reflection&.options&.include?(:through) && # regular singular association, or one-level through association
188
+ elsif !column.association.source_reflection&.through? && # regular singular association, or one-level through association
187
189
  !v.is_a?(Array)
188
190
  record.send(:"#{k}=", column.association.klass.find(v))
189
191
 
@@ -6,7 +6,7 @@ module ActiveScaffold::DataStructures::Association
6
6
  klass.reflect_on_all_associations
7
7
  end
8
8
 
9
- delegate :collection?, :polymorphic?, :association_primary_key, :foreign_type, :table_name, :nested?, :scope, to: :@association
9
+ delegate :collection?, :polymorphic?, :association_primary_key, :foreign_type, :table_name, :nested?, :scope, :class_name, to: :@association
10
10
 
11
11
  def through?
12
12
  @association.options[:through].present?
@@ -17,11 +17,11 @@ module ActiveScaffold::DataStructures::Association
17
17
  end
18
18
 
19
19
  def through_reflection
20
- @association.through_reflection if through?
20
+ @through_reflection ||= self.class.new(@association.through_reflection) if through?
21
21
  end
22
22
 
23
23
  def source_reflection
24
- @association.source_reflection if through?
24
+ @source_reflection ||= self.class.new(@association.source_reflection) if through?
25
25
  end
26
26
 
27
27
  def inverse_klass
@@ -746,10 +746,14 @@ module ActiveScaffold::DataStructures
746
746
 
747
747
  def valid_action_ui_params?(value)
748
748
  if value.is_a?(Array)
749
- value.size <= 2 && value[0].is_a?(Symbol) && (value[1].nil? || value[1].is_a?(Hash))
749
+ value.size <= 2 && valid_form_ui?(value[0]) && (value[1].nil? || value[1].is_a?(Hash))
750
750
  else
751
- value.nil? || value.is_a?(Symbol)
751
+ valid_form_ui?(value)
752
752
  end
753
753
  end
754
+
755
+ def valid_form_ui?(value)
756
+ value.nil? || value.is_a?(Symbol)
757
+ end
754
758
  end
755
759
  end
@@ -104,8 +104,8 @@ module ActiveScaffold::DataStructures
104
104
  # RatesController has employee in create action columns (reverse is vendor, and through association employee is in create form).
105
105
  def readonly_through_association?(columns)
106
106
  return false unless through_association?
107
- return true if association.through_reflection.options[:through] # create not possible, too many levels
108
- return true if association.source_reflection.options[:through] # create not possible, too many levels
107
+ return true if association.through_reflection.through? # create not possible, too many levels
108
+ return true if association.source_reflection.through? # create not possible, too many levels
109
109
  return false if create_through_singular? # create allowed, AS has code for this
110
110
  return false unless association.source_reflection.collection? # create allowed if source is singular, rails creates joint model
111
111
 
@@ -114,7 +114,7 @@ module ActiveScaffold::DataStructures
114
114
  end
115
115
 
116
116
  def create_through_singular?
117
- association.through_singular? && source_reflection.reverse
117
+ association.through_singular? && association.source_reflection.reverse
118
118
  end
119
119
 
120
120
  def create_with_parent?
@@ -125,10 +125,6 @@ module ActiveScaffold::DataStructures
125
125
  end
126
126
  end
127
127
 
128
- def source_reflection
129
- @source_reflection ||= ActiveScaffold::DataStructures::Association::ActiveRecord.new(association.source_reflection)
130
- end
131
-
132
128
  def through_association?
133
129
  association.through?
134
130
  end
@@ -245,7 +245,7 @@ module ActiveScaffold
245
245
  def logical_search_condition(column, search, parser = nil)
246
246
  model = column.active_record_class
247
247
  subquery = alias_query_for_same_table_exists(model.all) if column.logical_search.any?(Hash)
248
- query = ::LogicalQueryParser.search(search, subquery || model, columns: column.logical_search, parser: parser)
248
+ query = ::LogicalQueryParser.search(search, subquery || model, column.logical_search, parser: parser)
249
249
  if subquery
250
250
  model.where(same_table_exists_subquery(query))
251
251
  else
@@ -167,15 +167,13 @@ module ActiveScaffold
167
167
  def build_associated(association, parent_record)
168
168
  if association.through? && association.through_reflection.collection?
169
169
  # build full chain, only check create_associated on initial parent_record
170
- parent_record = build_associated(association.class.new(association.through_reflection), parent_record)
171
- source_assoc = association.class.new(association.source_reflection)
172
- build_associated(source_assoc, parent_record).tap do |record|
173
- save_record_to_association(record, source_assoc.reverse_association, parent_record) # set inverse
170
+ parent_record = build_associated(association.through_reflection, parent_record)
171
+ build_associated(association.source_reflection, parent_record).tap do |record|
172
+ save_record_to_association(record, association.source_reflection.reverse_association, parent_record) # set inverse
174
173
  end
175
174
  elsif association.through? # through belongs_to/has_one
176
175
  parent_record = parent_record.send(association.through_reflection.name)
177
- source_assoc = association.class.new(association.source_reflection)
178
- build_associated(source_assoc, parent_record)
176
+ build_associated(association.source_reflection, parent_record)
179
177
  elsif association.collection?
180
178
  parent_record.send(association.name).build
181
179
  elsif association.belongs_to? || parent_record.new_record? || parent_record.send(association.name).nil?
@@ -4,7 +4,7 @@ module ActiveScaffold
4
4
  module Version
5
5
  MAJOR = 4
6
6
  MINOR = 2
7
- PATCH = 1
7
+ PATCH = 2
8
8
  FIX = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, FIX].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-09 00:00:00.000000000 Z
11
+ date: 2026-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dartsass-sprockets