brick 1.0.209 → 1.0.211

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: 9727d5ff3dbf5edcb8ce91b03d0570eec5eb2e0f9ae2c4f456d9d50779321fc9
4
- data.tar.gz: 32b32f909110d6eca464c775d9725ad049fabf8591daab1088da007ae9a95c5a
3
+ metadata.gz: 7950119f788fe1cac3fde68806f2b4a1145da0cf17ff0d47363b102be9c69933
4
+ data.tar.gz: 33bb7d89a0744890d4450afde332dbd0f0635a8d3acd0beb4107cf4e44ff9718
5
5
  SHA512:
6
- metadata.gz: 1931290e472f472d93e1536e6517a3865bcc1acd23d15156d48e52c7f35987183b274c8a7c2ac00f09f2f6ac9a4d5663071c84ae4c896de6b4c0069d4a06b1da
7
- data.tar.gz: 5064ef883fb66feb187fe80a92b3ec700da04feef0f390d720b51497f086bbc1062e505cd467d3624fadb6102bc8dec49b0b6b16a1c04a1a1ceb34e50f4f9ff5
6
+ metadata.gz: 959c6ada7e03de34f566ad6059a4431ea66d2be9f12764de3edb3760074a70f3e91354e9052bc3c1a74eed4d5d7a274a78cf490195815b736b02f282ffe03d47
7
+ data.tar.gz: a87abaf8c878fecda93fc6751bae171e5194b6b63d933f83ba331191aee701859d3022754f68af3d730c25add0cc0a8174246fd18913040bed75ec700ba2b543
@@ -72,7 +72,7 @@ module ActiveRecord
72
72
 
73
73
  def real_model(params)
74
74
  if params && (sub_model = params.fetch(type_col = inheritance_column, nil))
75
- sub_model = sub_model.first if sub_model.is_a?(Array) # Support the params style that gets returned from #brick_select
75
+ sub_model = sub_model.first if sub_model.is_a?(Array) # Support the params style that gets returned from #_brick_querying
76
76
  # Make sure the chosen model is really the same or a subclass of this model
77
77
  (possible_model = sub_model.constantize) <= self ? possible_model : self
78
78
  else
@@ -92,11 +92,49 @@ module ActiveRecord
92
92
  reflect_on_association(assoc).foreign_type || "#{assoc}_type"
93
93
  end
94
94
 
95
- def _brick_all_fields
96
- rtans = if respond_to?(:rich_text_association_names)
97
- rich_text_association_names&.map { |rtan| rtan.to_s.start_with?('rich_text_') ? rtan[10..-1] : rtan }
98
- end
99
- columns_hash.keys.map(&:to_sym) + (rtans || [])
95
+ def _brick_all_fields(skip_id = nil)
96
+ col_names = columns_hash.keys
97
+ # If it's a composite primary key then allow all the values through
98
+ # TODO: Should disallow any autoincrement / SERIAL columns
99
+ if skip_id && (pk_as_array = _pk_as_array).length == 1
100
+ col_names -= _pk_as_array
101
+ end
102
+ hoa, hma, rtans = _activestorage_actiontext_fields
103
+ col_names.map(&:to_sym) + hoa + hma.map { |as| { as => [] } } + rtans.values
104
+ end
105
+
106
+ # Return three lists of fields for this model --
107
+ # has_one_attached, has_many_attached, and has_rich_text
108
+ def _activestorage_actiontext_fields
109
+ fields = [[], [], {}]
110
+ if !(self <= ActiveStorage::Blob) && respond_to?(:generated_association_methods) # ActiveStorage
111
+ generated_association_methods.instance_methods.each do |method_sym|
112
+ method_str = method_sym.to_s
113
+ fields[0] << method_str[0..-13].to_sym if method_str.end_with?('_attachment=') # has_one_attached
114
+ fields[1] << method_str[0..-14].to_sym if method_str.end_with?('_attachments=') # has_many_attached
115
+ end
116
+ end
117
+ if respond_to?(:rich_text_association_names) # ActionText
118
+ rich_text_association_names&.each do |rtan| # has_rich_text
119
+ rtan_str = rtan.to_s
120
+ fields[2][rtan] = rtan_str.start_with?('rich_text_') ? rtan_str[10..-1].to_sym : rtan
121
+ end
122
+ end
123
+ fields
124
+ end
125
+
126
+ def _active_storage_name(col_name)
127
+ if Object.const_defined?('ActiveStorage') && (self <= ActiveStorage::Attachment || self <= ActiveStorage::Blob)
128
+ if (col_str = col_name.to_s).end_with?('_attachments')
129
+ col_str[0..-13]
130
+ elsif col_str.end_with?('_blobs')
131
+ col_str[0..-7]
132
+ end
133
+ end
134
+ end
135
+
136
+ def _pk_as_array
137
+ self.primary_key.is_a?(Array) ? self.primary_key : [self.primary_key]
100
138
  end
101
139
 
102
140
  def _br_quoted_name(name)
@@ -147,8 +185,8 @@ module ActiveRecord
147
185
  skip_columns = _brick_get_fks + (::Brick.config.metadata_columns || []) + [primary_key]
148
186
  dsl = if (descrip_col = columns.find { |c| [:boolean, :binary, :xml].exclude?(c.type) && skip_columns.exclude?(c.name) })
149
187
  "[#{descrip_col.name}]"
150
- elsif (pk_parts = self.primary_key.is_a?(Array) ? self.primary_key : [self.primary_key])
151
- "#{name} ##{pk_parts.map { |pk_part| "[#{pk_part}]" }.join(', ')}"
188
+ else
189
+ "#{name} ##{_pk_as_array.map { |pk_part| "[#{pk_part}]" }.join(', ')}"
152
190
  end
153
191
  ::Brick.config.model_descrips[name] = dsl
154
192
  end
@@ -491,17 +529,12 @@ module ActiveRecord
491
529
  [order_by, order_by_txt]
492
530
  end
493
531
 
494
- def self.brick_select(*args, params: {}, brick_col_names: false, **kwargs)
495
- selects = if args[0].is_a?(Array)
496
- other_args = args[1..-1]
497
- args[0]
498
- else
499
- other_args = []
500
- args
501
- end
502
- (relation = all).brick_select(selects, *other_args,
503
- params: params, brick_col_names: brick_col_names, **kwargs)
504
- relation.select(selects)
532
+ def self.brick_select(*args, **kwargs)
533
+ all.brick_select(*args, **kwargs)
534
+ end
535
+
536
+ def self.brick_pluck(*args, withhold_ids: true, **kwargs)
537
+ all.brick_pluck(*args, withhold_ids: withhold_ids, **kwargs)
505
538
  end
506
539
 
507
540
  def self.brick_where(*args)
@@ -559,7 +592,7 @@ module ActiveRecord
559
592
  # If it's a CollectionProxy (which inherits from Relation) then need to dig
560
593
  # out the core Relation object which is found in the association scope.
561
594
  brick_rel = is_a?(ActiveRecord::Associations::CollectionProxy) ? scope : self
562
- brick_rel = brick_rel.dup if do_dup
595
+ brick_rel = (@_brick_rel_dup ||= brick_rel.dup) if do_dup
563
596
  # Start out with a hash that has only the root table name
564
597
  brick_rel.instance_variable_set(:@_brick_links, bl = { '' => table_name })
565
598
  brick_rel.arel.ast if do_dup # Walk the AST tree in order to capture all the other correlation names
@@ -567,10 +600,22 @@ module ActiveRecord
567
600
  end
568
601
  end
569
602
 
570
- def brick_select(*args, params: {}, order_by: nil, translations: {},
571
- join_array: ::Brick::JoinArray.new,
572
- cust_col_override: nil,
573
- brick_col_names: true)
603
+ def brick_select(*args, **kwargs)
604
+ selects = args[0].is_a?(Array) ? args[0] : args
605
+ _brick_querying(selects, **kwargs)
606
+ select(selects)
607
+ end
608
+
609
+ def brick_pluck(*args, withhold_ids: true, **kwargs)
610
+ selects = args[0].is_a?(Array) ? args[0] : args
611
+ _brick_querying(selects, withhold_ids: withhold_ids, **kwargs)
612
+ pluck(selects)
613
+ end
614
+
615
+ def _brick_querying(*args, withhold_ids: nil, params: {}, order_by: nil, translations: {},
616
+ join_array: ::Brick::JoinArray.new,
617
+ cust_col_override: nil,
618
+ brick_col_names: nil)
574
619
  selects = args[0].is_a?(Array) ? args[0] : args
575
620
  if selects.present? && cust_col_override.nil? # See if there's any fancy ones in the select list
576
621
  idx = 0
@@ -654,13 +699,13 @@ module ActiveRecord
654
699
  "'<#{typ.end_with?('_TYP') ? typ[0..-5] : typ}>' AS #{col.name}"
655
700
  end
656
701
  end
657
- else # Having some select columns chosen, add any missing always_load_fields for this model ...
702
+ elsif !withhold_ids # Having some select columns chosen, add any missing always_load_fields for this model ...
658
703
  this_model = klass
659
704
  loop do
660
705
  ::Brick.config.always_load_fields.fetch(this_model.name, nil)&.each do |alf|
661
706
  selects << alf unless selects.include?(alf)
662
707
  end
663
- # ... plus any and all STI superclasses it may inherit from
708
+ # ... plus ALF fields from any and all STI superclasses it may inherit from
664
709
  break if (this_model = this_model.superclass).abstract_class? || this_model == ActiveRecord::Base
665
710
  end
666
711
  end
@@ -673,15 +718,16 @@ module ActiveRecord
673
718
  end
674
719
  end
675
720
 
676
- core_selects = selects.dup
721
+ # core_selects = selects.dup
677
722
  id_for_tables = Hash.new { |h, k| h[k] = [] }
678
723
  field_tbl_names = Hash.new { |h, k| h[k] = {} }
679
724
  used_col_aliases = {} # Used to make sure there is not a name clash
680
725
 
681
726
  # CUSTOM COLUMNS
682
727
  # ==============
683
- (cust_col_override || klass._br_cust_cols).each do |k, cc|
684
- if respond_to?(k) # Name already taken?
728
+ (cust_col_override || (!withhold_ids && klass._br_cust_cols))&.each do |k, cc|
729
+ brick_links # Intentionally create a relation duplicate
730
+ if @_brick_rel_dup.respond_to?(k) # Name already taken?
685
731
  # %%% Use ensure_unique here in this kind of fashion:
686
732
  # cnstr_name = ensure_unique(+"(brick) #{for_tbl}_#{pri_tbl}", nil, bts, hms)
687
733
  # binding.pry
@@ -730,12 +776,14 @@ module ActiveRecord
730
776
  selects << "#{_br_quoted_name(tbl_name)}.#{_br_quoted_name(cc_part.last)} AS #{_br_quoted_name(col_alias)}"
731
777
  cc_part << col_alias
732
778
  end
733
- # Add a key column unless we've already got it
734
- if key_alias && !used_col_aliases.key?(key_alias)
735
- selects << "#{_br_quoted_name(key_tbl_name)}.#{_br_quoted_name(dest_pk)} AS #{_br_quoted_name(key_alias)}"
736
- used_col_aliases[key_alias] = nil
779
+ unless withhold_ids
780
+ # Add a key column unless we've already got it
781
+ if key_alias && !used_col_aliases.key?(key_alias)
782
+ selects << "#{_br_quoted_name(key_tbl_name)}.#{_br_quoted_name(dest_pk)} AS #{_br_quoted_name(key_alias)}"
783
+ used_col_aliases[key_alias] = nil
784
+ end
785
+ cc[2] = key_alias ? [key_klass, key_alias] : nil
737
786
  end
738
- cc[2] = key_alias ? [key_klass, key_alias] : nil
739
787
  end
740
788
 
741
789
  # LEFT OUTER JOINs
@@ -751,7 +799,7 @@ module ActiveRecord
751
799
  # %%% Strangely in Rails 7.1 on a slower system then very rarely brick_link comes back nil...
752
800
  brick_link = brick_links[sel_col.first]
753
801
  field_tbl_name = brick_link&.split('.')&.last ||
754
- # ... so here's a best-effort guess for what the table name might be.
802
+ # ... so if it is nil then here's a best-effort guess as to what the table name might be.
755
803
  klass.reflect_on_association(sel_col.first)&.klass&.table_name
756
804
  # If it's Oracle, quote any AREL aliases that had been applied
757
805
  field_tbl_name = "\"#{field_tbl_name}\"" if ::Brick.is_oracle && brick_links.values.include?(field_tbl_name)
@@ -831,6 +879,8 @@ module ActiveRecord
831
879
  end
832
880
  through_sources.push(src_ref) unless src_ref.belongs_to?
833
881
  from_clause = +"#{_br_quoted_name(through_sources.first.table_name)} br_t0"
882
+ # ActiveStorage will not get the correct count unless we do some extra filtering later
883
+ tbl_nm = 'br_t0' if Object.const_defined?('ActiveStorage') && through_sources.first.klass <= ActiveStorage::Attachment
834
884
  fk_col = through_sources.shift.foreign_key
835
885
 
836
886
  idx = 0
@@ -924,10 +974,14 @@ module ActiveRecord
924
974
  tbl_nm = hm.macro == :has_and_belongs_to_many ? hm.join_table : hm.table_name
925
975
  hm_table_name = _br_quoted_name(tbl_nm)
926
976
  end
977
+ # ActiveStorage has_many_attached needs a bit more filtering
978
+ if (k_str = hm.klass._active_storage_name(k))
979
+ where_ct_clause = "WHERE #{_br_quoted_name("#{tbl_nm}.name")} = '#{k_str}' "
980
+ end
927
981
  group_bys = ::Brick.is_oracle || is_mssql ? hm_selects : (1..hm_selects.length).to_a
928
982
  join_clause = "LEFT OUTER
929
983
  JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#{s}") }.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}#{_br_quoted_name(count_column)
930
- }) AS c_t_ FROM #{from_clause || hm_table_name} GROUP BY #{group_bys.join(', ')}) #{_br_quoted_name(tbl_alias)}"
984
+ }) AS c_t_ FROM #{from_clause || hm_table_name} #{where_ct_clause}GROUP BY #{group_bys.join(', ')}) #{_br_quoted_name(tbl_alias)}"
931
985
  self.joins_values |= ["#{join_clause} ON #{on_clause.join(' AND ')}"] # Same as: joins!(...)
932
986
  end unless cust_col_override
933
987
  while (n = nix.pop)
@@ -1022,9 +1076,10 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
1022
1076
  selects << 'customer_id' if klass.name == 'Pay::Subscription' && Pay::Subscription.columns_hash.key?('customer_id')
1023
1077
 
1024
1078
  pieces, my_dsl = klass.brick_parse_dsl(join_array = ::Brick::JoinArray.new, [], translations = {}, false, nil, true)
1025
- brick_select(
1079
+ _brick_querying(
1026
1080
  selects, where_values_hash, nil, translations: translations, join_array: join_array,
1027
- cust_col_override: { '_br' => (descrip_cols = [pieces, my_dsl]) }
1081
+ cust_col_override: { '_br' => (descrip_cols = [pieces, my_dsl]) },
1082
+ brick_col_names: true
1028
1083
  )
1029
1084
  order_values = "#{_br_quoted_name(klass.table_name)}.#{_br_quoted_name(klass.primary_key)}"
1030
1085
  [self.select(selects), descrip_cols]
@@ -2246,9 +2301,10 @@ class Object
2246
2301
 
2247
2302
  ar_relation = ActiveRecord.version < Gem::Version.new('4') ? real_model.preload : real_model.all
2248
2303
  params['_brick_is_api'] = true if (is_api = request.format == :js || current_api_root)
2249
- @_brick_params = ar_relation.brick_select((selects ||= []), params: params, order_by: order_by,
2250
- translations: (translations = {}),
2251
- join_array: (join_array = ::Brick::JoinArray.new))
2304
+ @_brick_params = ar_relation._brick_querying((selects ||= []), params: params, order_by: order_by,
2305
+ translations: (translations = {}),
2306
+ join_array: (join_array = ::Brick::JoinArray.new),
2307
+ brick_col_names: true)
2252
2308
 
2253
2309
  if is_api # Asking for JSON?
2254
2310
  # Apply column renaming
@@ -2342,7 +2398,7 @@ class Object
2342
2398
  _, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk, true)) if pk
2343
2399
  code << " def index\n"
2344
2400
  code << " @#{plural_table_name} = #{model.name}#{pk&.present? ? ".order(#{order_by_txt.join(', ')})" : '.all'}\n"
2345
- code << " @#{plural_table_name}.brick_select(params)\n"
2401
+ code << " @#{plural_table_name}._brick_querying(params, brick_col_names: true)\n"
2346
2402
  code << " end\n"
2347
2403
 
2348
2404
  is_pk_string = nil
@@ -2357,6 +2413,8 @@ class Object
2357
2413
  end
2358
2414
  end
2359
2415
 
2416
+ params_name_sym = (params_name = "#{singular_table_name}_params").to_sym
2417
+
2360
2418
  # By default, views get marked as read-only
2361
2419
  # unless model.readonly # (relation = relations[model.table_name]).key?(:isView)
2362
2420
  code << " def new\n"
@@ -2364,7 +2422,11 @@ class Object
2364
2422
  code << " end\n"
2365
2423
  self.define_method :new do
2366
2424
  _schema, @_is_show_schema_list = ::Brick.set_db_schema(params)
2367
- new_params = model.attribute_names.each_with_object({}) do |a, s|
2425
+ new_params = begin
2426
+ send(params_name_sym)
2427
+ rescue
2428
+ end
2429
+ new_params ||= model.attribute_names.each_with_object({}) do |a, s|
2368
2430
  if (val = params["__#{a}"])
2369
2431
  # val = case new_obj.class.column_for_attribute(a).type
2370
2432
  # when :datetime, :date, :time, :timestamp
@@ -2385,8 +2447,6 @@ class Object
2385
2447
  add_csp_hash
2386
2448
  end
2387
2449
 
2388
- params_name_sym = (params_name = "#{singular_table_name}_params").to_sym
2389
-
2390
2450
  code << " def create\n"
2391
2451
  code << " @#{singular_table_name} = #{model.name}.create(#{params_name})\n"
2392
2452
  code << " end\n"
@@ -2403,8 +2463,7 @@ class Object
2403
2463
  end
2404
2464
  render json: { result: ::Brick.unexclude_column(table_name, col) }
2405
2465
  else
2406
- @_lookup_context.instance_variable_set("@#{singular_table_name}".to_sym,
2407
- (created_obj = model.send(:create, send(params_name_sym))))
2466
+ created_obj = model.send(:create, send(params_name_sym))
2408
2467
  @_lookup_context.instance_variable_set(:@_brick_model, model)
2409
2468
  if created_obj.errors.empty?
2410
2469
  index
@@ -2481,7 +2540,16 @@ class Object
2481
2540
  if (upd_hash ||= upd_params).fetch(model.inheritance_column, nil)&.strip == ''
2482
2541
  upd_hash[model.inheritance_column] = nil
2483
2542
  end
2484
- obj.send(:update, upd_hash || upd_params)
2543
+ # Do not clear out a has_many_attached field if it already has an entry and nothing is supplied
2544
+ hoa, hma, rtans = model._activestorage_actiontext_fields
2545
+ all_params = params[singular_table_name]
2546
+ hma.each do |hma_field|
2547
+ if upd_hash.fetch(hma_field) == [''] && # No new attachments...
2548
+ all_params&.fetch("_brick_attached_#{hma_field}", nil) # ...and there is something existing
2549
+ upd_hash.delete(hma_field)
2550
+ end
2551
+ end
2552
+ obj.send(:update, upd_hash)
2485
2553
  if obj.errors.any? # Surface errors to the user in a flash message
2486
2554
  flash.now.alert = (obj.errors.errors.map { |err| "<b>#{err.attribute}</b> #{err.message}" }.join(', '))
2487
2555
  end
@@ -2531,7 +2599,7 @@ class Object
2531
2599
 
2532
2600
  if is_need_params
2533
2601
  code << " def #{params_name}\n"
2534
- permits_txt = model._brick_find_permits(model, permits = model._brick_all_fields)
2602
+ permits_txt = model._brick_find_permits(model, permits = model._brick_all_fields(true))
2535
2603
  code << " params.require(:#{require_name = model.name.underscore.tr('/', '_')
2536
2604
  }).permit(#{permits_txt.map(&:inspect).join(', ')})\n"
2537
2605
  code << " end\n"
@@ -641,6 +641,11 @@ window.addEventListener(\"popstate\", linkSchemas);
641
641
  type_col = hm_assoc.inverse_of&.foreign_type || hm_assoc.type
642
642
  keys << [type_col, poly_type]
643
643
  end
644
+ # ActiveStorage has_one_attached and has_many_attached needs additional filtering on the name
645
+ if (as_name = hm_assoc.klass&._active_storage_name(hm_assoc.name)) # ActiveStorage HMT
646
+ prefix = 'attachments.' if hm_assoc.through_reflection&.klass&.<= ActiveStorage::Attachment
647
+ keys << ["#{prefix}name", as_name]
648
+ end
644
649
  keys.to_h
645
650
  end
646
651
 
@@ -1506,7 +1511,7 @@ end
1506
1511
 
1507
1512
  if (pk = hm.first.klass.primary_key)
1508
1513
  hm_singular_name = (hm_name = hm.first.name.to_s).singularize.underscore
1509
- obj_br_pk = (pk.is_a?(Array) ? pk : [pk]).each_with_object([]) { |pk_part, s| s << "br_#{hm_singular_name}.#{pk_part}" }.join(', ')
1514
+ obj_br_pk = hm.first.klass._pk_as_array.map { |pk_part| "br_#{hm_singular_name}.#{pk_part}" }.join(', ')
1510
1515
  poly_fix = if (poly_type = (hm.first.options[:as] && hm.first.type))
1511
1516
  "
1512
1517
  # Let's fix an unexpected \"feature\" of AR -- when going through a polymorphic has_many
@@ -110,6 +110,41 @@ module Brick::Rails::FormBuilder
110
110
  ::Brick::Rails.display_binary(val)
111
111
  end
112
112
  end
113
+ when :file, :files
114
+ if attached = begin
115
+ self.object.send(method)
116
+ rescue
117
+ end
118
+ # Show any existing image(s)
119
+ existing = []
120
+ got_one = nil
121
+ (attached.respond_to?(:attachments) ? attached.attachments : [attached]).each do |attachment|
122
+ next unless (blob = attachment.blob)
123
+
124
+ existing << blob.key
125
+ out << "#{blob.filename}<br>"
126
+ url = begin
127
+ self.object.send(method)&.url
128
+ rescue StandardError => e
129
+ # Another possible option:
130
+ # Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
131
+ Rails.application.routes.url_helpers.rails_storage_proxy_path(attachment, only_path: true)
132
+ end
133
+ out << if url
134
+ "<img src=\"#{url}\" title=\"#{val}\">"
135
+ else # Convert the raw binary to a Base64 image
136
+ ::Brick::Rails.display_binary(attachment.download, 500_000)
137
+ end
138
+ got_one = true
139
+ out << '<br>'
140
+ end
141
+ out << 'Update: ' if got_one
142
+ end
143
+ out << self.hidden_field("_brick_attached_#{method}", value: existing.join(',')) unless existing.blank?
144
+ # Render a "Choose File(s)" input element
145
+ args = [method.to_sym]
146
+ args << { multiple: true } if col&.type == :files
147
+ out << self.file_field(*args)
113
148
  when :primary_key
114
149
  is_revert = false
115
150
  when :json, :jsonb
@@ -445,19 +445,25 @@ function onImagesLoaded(event) {
445
445
  obj.send("#{model.brick_foreign_type(v.first)}=", v[1].first&.first&.name)
446
446
  end
447
447
  end if obj.new_record?
448
- rtans = model.rich_text_association_names if model.respond_to?(:rich_text_association_names)
449
- (model.column_names + (rtans || [])).each do |k|
448
+ hoa, hma, rtans = model._activestorage_actiontext_fields
449
+ (model.column_names + hoa + hma + rtans.keys).each do |k|
450
450
  pk_pos = (pk.index(k)&.+ 1)
451
451
  next if (pk_pos && pk.length == 1 && !bts.key?(k)) ||
452
452
  ::Brick.config.metadata_columns.include?(k)
453
453
 
454
454
  col = model.columns_hash[k]
455
- if !col && rtans&.include?(k)
456
- k = k[10..-1] if k.start_with?('rich_text_')
457
- col = (rt_col ||= ActiveRecord::ConnectionAdapters::Column.new(
458
- '', nil, ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: 'varchar', type: :text)
459
- )
460
- )
455
+ if !col
456
+ kwargs = if hoa.include?(k) # has_one_attached
457
+ { sql_type: 'binary', type: :file }
458
+ elsif hma.include?(k) # has_many_attached
459
+ { sql_type: 'binary', type: :files }
460
+ elsif rtans&.key?(k) # has_rich_text
461
+ k = rtans[k]
462
+ { sql_type: 'varchar', type: :text }
463
+ end
464
+ col = (ActiveRecord::ConnectionAdapters::Column.new(
465
+ '', nil, ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(**kwargs)
466
+ )) if kwargs
461
467
  end
462
468
  val = obj.attributes[k]
463
469
  out << "
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 209
8
+ TINY = 211
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.209
4
+ version: 1.0.211
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-20 00:00:00.000000000 Z
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  - !ruby/object:Gem::Version
286
286
  version: 1.3.6
287
287
  requirements: []
288
- rubygems_version: 3.2.33
288
+ rubygems_version: 3.1.6
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Create a Rails app from data alone