brick 1.0.27 → 1.0.28

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
2
  SHA256:
3
- metadata.gz: '097fb194c2b1323cd051669f362d86492d9c768f1cbccf06c2fdc45a7f266e1e'
4
- data.tar.gz: 72746f153d073256b8be063e90c28da85a50e11865250f2570d501ff320431b3
3
+ metadata.gz: ab7e6a8198638a0e6d3cde289db17d107e699fad2b4b5a200703cb1982d19569
4
+ data.tar.gz: 708360bb9463e45c8f7fece60dc762dc65b2b3893d8044ffce9ee87e33f63b80
5
5
  SHA512:
6
- metadata.gz: 83d0c40c0af17d314d6b4cd7ab0e312bce1c8d57bdd0992da1b54fa8a3e829852c6fd800c34f3bd35f3a3306bda736dc99d14af19009926bf65971a5d4904717
7
- data.tar.gz: c82b9c31ffe3a00e701e22a3f69c85e7b60e0b3b6d24e95df7fe3f8afb85b00ab7515e0befab7dd37e8a25924274e663127b953dab8eb64041d834aa39de4bc1
6
+ metadata.gz: 92229661eff9aac30ec7fad96603bc649a122131956e8632562e22d11c8bae67db0272ec5453ab2cc233bd11f7ab72222c3520f2acceecb83e35d4c54cbd8f4d
7
+ data.tar.gz: ddc169b2effaf58e60861d0153f191f6f1e2f11d459363a000da2c1f44c1583c8cd037f78269c238a84de58e04d7633c7a7ecbf046c08ef48fdaf5fb01de76a3
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Some future enhancement ideas:
4
+
3
5
  # Have markers on HM relationships to indicate "load this one every time" or "lazy load it" or "don't bother"
4
6
  # Others on BT to indicate "this is a lookup"
5
7
 
@@ -18,7 +20,7 @@
18
20
  # Sensitive stuff -- make a lock icon thing so people don't accidentally edit stuff
19
21
 
20
22
  # Static text that can go on pages - headings and footers and whatever
21
- # Eventually some indication about if it should be a paginated table / unpaginated / a list of just some fields / etc
23
+ # Eventually some indication about if it should be a paginated table / unpaginated / a list of just some fields / columns shown in a different sequence / etc
22
24
 
23
25
  # Grid where each cell is one field and then when you mouse over then it shows a popup other table of detail inside
24
26
 
@@ -32,6 +34,9 @@
32
34
 
33
35
  # Currently quadrupling up routes
34
36
 
37
+ # Modal pop-up things for editing large text / date ranges / hierarchies of data
38
+
39
+ # For recognised self-references, have the show page display all related objects up to the parent (or the start of a circular reference)
35
40
 
36
41
  # ==========================================================
37
42
  # Dynamically create model or controller classes when needed
@@ -62,6 +67,14 @@ module ActiveRecord
62
67
  false
63
68
  end
64
69
 
70
+ def self._brick_primary_key(relation = nil)
71
+ return instance_variable_get(:@_brick_primary_key) if instance_variable_defined?(:@_brick_primary_key)
72
+
73
+ pk = primary_key.is_a?(String) ? [primary_key] : primary_key || []
74
+ # Just return [] if we're missing any part of the primary key. (PK is usually just "id")
75
+ @_brick_primary_key ||= pk.any? { |pk_part| !relation[:cols].key?(pk_part) } ? [] : pk
76
+ end
77
+
65
78
  # Used to show a little prettier name for an object
66
79
  def self.brick_get_dsl
67
80
  # If there's no DSL yet specified, just try to find the first usable column on this model
@@ -344,17 +357,13 @@ module ActiveRecord
344
357
  next if chains[k1].nil?
345
358
 
346
359
  tbl_name = field_tbl_names[v.first][k1] ||= shift_or_first(chains[k1])
347
- # if (col_name = v1[1].last&.last) # col_name is weak when there are multiple, using sel_col.last instead
348
360
  field_tbl_name = nil
349
- v1.map { |x|
350
- [translations[x[0..-2].map(&:to_s).join('.')], x.last]
351
- }.each_with_index do |sel_col, idx|
352
- field_tbl_name ||= field_tbl_names[v.first][sel_col.first] ||= shift_or_first(chains[sel_col.first])
361
+ v1.map { |x| [translations[x[0..-2].map(&:to_s).join('.')], x.last] }.each_with_index do |sel_col, idx|
362
+ field_tbl_name = field_tbl_names[v.first][sel_col.first] ||= shift_or_first(chains[sel_col.first])
353
363
 
354
364
  selects << "#{"#{field_tbl_name}.#{sel_col.last}"} AS \"#{(col_alias = "_brfk_#{v.first}__#{sel_col.last}")}\""
355
365
  v1[idx] << col_alias
356
366
  end
357
- # end
358
367
 
359
368
  unless id_for_tables.key?(v.first)
360
369
  # Accommodate composite primary key by allowing id_col to come in as an array
@@ -524,7 +533,7 @@ class Object
524
533
  singular_table_name = ActiveSupport::Inflector.underscore(model_name)
525
534
 
526
535
  # Adjust for STI if we know of a base model for the requested model name
527
- table_name = if (base_model = ::Brick.sti_models[model_name]&.fetch(:base, ::Brick.existing_stis[model_name]&.constantize))
536
+ table_name = if (base_model = ::Brick.sti_models[model_name]&.fetch(:base, nil) || ::Brick.existing_stis[model_name]&.constantize)
528
537
  base_model.table_name
529
538
  else
530
539
  ActiveSupport::Inflector.pluralize(singular_table_name)
@@ -565,7 +574,7 @@ class Object
565
574
  return
566
575
  end
567
576
 
568
- if (base_model = ::Brick.sti_models[model_name]&.fetch(:base, ::Brick.existing_stis[model_name]&.constantize))
577
+ if (base_model = ::Brick.sti_models[model_name]&.fetch(:base, nil) || ::Brick.existing_stis[model_name]&.constantize)
569
578
  is_sti = true
570
579
  else
571
580
  base_model = ::Brick.config.models_inherit_from || ActiveRecord::Base
@@ -585,16 +594,14 @@ class Object
585
594
  code << " def self.is_view?; true; end\n"
586
595
  end
587
596
 
588
- # Missing a primary key column? (Usually "id")
589
- ar_pks = primary_key.is_a?(String) ? [primary_key] : primary_key || []
590
597
  db_pks = relation[:cols]&.map(&:first)
591
- has_pk = ar_pks.length.positive? && (db_pks & ar_pks).sort == ar_pks.sort
598
+ has_pk = _brick_primary_key(relation).length.positive? && (db_pks & _brick_primary_key).sort == _brick_primary_key.sort
592
599
  our_pks = relation[:pkey].values.first
593
600
  # No primary key, but is there anything UNIQUE?
594
601
  # (Sort so that if there are multiple UNIQUE constraints we'll pick one that uses the least number of columns.)
595
602
  our_pks = relation[:ukeys].values.sort { |a, b| a.length <=> b.length }.first unless our_pks&.present?
596
603
  if has_pk
597
- code << " # Primary key: #{ar_pks.join(', ')}\n" unless ar_pks == ['id']
604
+ code << " # Primary key: #{_brick_primary_key.join(', ')}\n" unless _brick_primary_key == ['id']
598
605
  elsif our_pks&.present?
599
606
  if our_pks.length > 1 && respond_to?(:'primary_keys=') # Using the composite_primary_keys gem?
600
607
  new_model_class.primary_keys = our_pks
@@ -614,10 +621,13 @@ class Object
614
621
  # The key in each hash entry (fk.first) is the constraint name
615
622
  inverse_assoc_name = (assoc = fk.last)[:inverse]&.fetch(:assoc_name, nil)
616
623
  if (invs = assoc[:inverse_table]).is_a?(Array)
617
- invs.each { |inv| build_bt_or_hm(relations, model_name, relation, hmts, assoc, inverse_assoc_name, inv, code) }
618
- else
619
- build_bt_or_hm(relations, model_name, relation, hmts, assoc, inverse_assoc_name, invs, code)
624
+ if assoc[:is_bt]
625
+ invs = invs.first # Just do the first one of what would be multiple identical polymorphic belongs_to
626
+ else
627
+ invs.each { |inv| build_bt_or_hm(relations, model_name, relation, hmts, assoc, inverse_assoc_name, inv, code) }
628
+ end
620
629
  end
630
+ build_bt_or_hm(relations, model_name, relation, hmts, assoc, inverse_assoc_name, invs, code) unless invs.is_a?(Array)
621
631
  hmts
622
632
  end
623
633
  hmts.each do |hmt_fk, fks|
@@ -644,7 +654,7 @@ class Object
644
654
  # # Not NULLables
645
655
  # # %%% For the minute we've had to pull this out because it's been troublesome implementing the NotNull validator
646
656
  # relation[:cols].each do |col, datatype|
647
- # if (datatype[3] && ar_pks.exclude?(col) && ::Brick.config.metadata_columns.exclude?(col)) ||
657
+ # if (datatype[3] && _brick_primary_key.exclude?(col) && ::Brick.config.metadata_columns.exclude?(col)) ||
648
658
  # ::Brick.config.not_nullables.include?("#{matching}.#{col}")
649
659
  # code << " validates :#{col}, not_null: true\n"
650
660
  # self.send(:validates, col.to_sym, { not_null: true })
@@ -741,13 +751,14 @@ class Object
741
751
  def build_controller(class_name, plural_class_name, model, relations)
742
752
  table_name = ActiveSupport::Inflector.underscore(plural_class_name)
743
753
  singular_table_name = ActiveSupport::Inflector.singularize(table_name)
754
+ pk = model._brick_primary_key(relations[table_name])
744
755
 
745
756
  code = +"class #{class_name} < ApplicationController\n"
746
757
  built_controller = Class.new(ActionController::Base) do |new_controller_class|
747
758
  Object.const_set(class_name.to_sym, new_controller_class)
748
759
 
749
760
  code << " def index\n"
750
- code << " @#{table_name} = #{model.name}#{model.primary_key ? ".order(#{model.primary_key.inspect})" : '.all'}\n"
761
+ code << " @#{table_name} = #{model.name}#{pk&.present? ? ".order(#{pk.inspect})" : '.all'}\n"
751
762
  code << " @#{table_name}.brick_select(params)\n"
752
763
  code << " end\n"
753
764
  self.protect_from_forgery unless: -> { self.request.format.js? }
@@ -765,7 +776,8 @@ class Object
765
776
  return
766
777
  end
767
778
 
768
- ar_relation = model.primary_key ? model.order("#{model.table_name}.#{model.primary_key}") : model.all
779
+ order = pk.each_with_object([]) { |pk_part, s| s << "#{model.table_name}.#{pk_part}" }
780
+ ar_relation = order.present? ? model.order("#{order.join(', ')}") : model.all
769
781
  @_brick_params = ar_relation.brick_select(params, (selects = []), (bt_descrip = {}), (hm_counts = {}), (join_array = ::Brick::JoinArray.new))
770
782
  # %%% Add custom HM count columns
771
783
  # %%% What happens when the PK is composite?
@@ -797,6 +809,10 @@ class Object
797
809
  code << " # (Define :new, :create)\n"
798
810
 
799
811
  if model.primary_key
812
+ if (schema = ::Brick.config.schema_to_analyse) && ::Brick.db_schemas&.include?(schema)
813
+ ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?;", schema)
814
+ end
815
+
800
816
  is_need_params = true
801
817
  # code << " # (Define :edit, and :destroy)\n"
802
818
  code << " def update\n"
@@ -871,12 +887,12 @@ module ActiveRecord::ConnectionHandling
871
887
  def _brick_reflect_tables
872
888
  if (relations = ::Brick.relations).empty?
873
889
  # Only for Postgres? (Doesn't work in sqlite3)
874
- # puts ActiveRecord::Base.connection.execute("SELECT current_setting('SEARCH_PATH')").to_a.inspect
890
+ # puts ActiveRecord::Base.execute_sql("SELECT current_setting('SEARCH_PATH')").to_a.inspect
875
891
 
876
892
  schema_sql = 'SELECT NULL AS table_schema;'
877
893
  case ActiveRecord::Base.connection.adapter_name
878
894
  when 'PostgreSQL'
879
- schema = 'public'
895
+ schema = 'public' # Too early at this point to be able to pick up: Brick.config.schema_to_analyse
880
896
  schema_sql = 'SELECT DISTINCT table_schema FROM INFORMATION_SCHEMA.tables;'
881
897
  when 'Mysql2'
882
898
  schema = ActiveRecord::Base.connection.current_database
@@ -920,7 +936,7 @@ module ActiveRecord::ConnectionHandling
920
936
  measures = []
921
937
  case ActiveRecord::Base.connection.adapter_name
922
938
  when 'PostgreSQL', 'SQLite' # These bring back a hash for each row because the query uses column aliases
923
- ActiveRecord::Base.connection.execute(sql).each do |r|
939
+ ActiveRecord::Base.execute_sql(sql).each do |r|
924
940
  # next if internal_views.include?(r['relation_name']) # Skip internal views such as v_all_assessments
925
941
  relation = relations[(relation_name = r['relation_name'])]
926
942
  relation[:isView] = true if r['table_type'] == 'VIEW'
@@ -939,7 +955,7 @@ module ActiveRecord::ConnectionHandling
939
955
  # puts "KEY! #{r['relation_name']}.#{col_name} #{r['key']} #{r['const']}" if r['key']
940
956
  end
941
957
  else # MySQL2 acts a little differently, bringing back an array for each row
942
- ActiveRecord::Base.connection.execute(sql).each do |r|
958
+ ActiveRecord::Base.execute_sql(sql).each do |r|
943
959
  # next if internal_views.include?(r['relation_name']) # Skip internal views such as v_all_assessments
944
960
  relation = relations[(relation_name = r[0])] # here relation represents a table or view from the database
945
961
  relation[:isView] = true if r[1] == 'VIEW' # table_type
@@ -1005,11 +1021,11 @@ module ActiveRecord::ConnectionHandling
1005
1021
  else
1006
1022
  end
1007
1023
  if sql
1008
- ::Brick.db_schemas = ActiveRecord::Base.connection.execute(schema_sql)
1024
+ ::Brick.db_schemas = ActiveRecord::Base.execute_sql(schema_sql)
1009
1025
  ::Brick.db_schemas = ::Brick.db_schemas.to_a unless ::Brick.db_schemas.is_a?(Array)
1010
1026
  ::Brick.db_schemas.map! { |row| row['table_schema'] } unless ::Brick.db_schemas.empty? || ::Brick.db_schemas.first.is_a?(String)
1011
1027
  ::Brick.db_schemas -= ['information_schema', 'pg_catalog']
1012
- ActiveRecord::Base.connection.execute(sql).each do |fk|
1028
+ ActiveRecord::Base.execute_sql(sql).each do |fk|
1013
1029
  fk = fk.values unless fk.is_a?(Array)
1014
1030
  ::Brick._add_bt_and_hm(fk, relations)
1015
1031
  end
@@ -1118,10 +1134,10 @@ module Brick
1118
1134
  return if is_class || ::Brick.config.exclude_hms&.any? { |exclusion| fk[0] == exclusion[0] && fk[1] == exclusion[1] && primary_table == exclusion[2] }
1119
1135
 
1120
1136
  if (assoc_hm = hms.fetch((hm_cnstr_name = "hm_#{cnstr_name}"), nil))
1121
- if assoc_bt[:fk].is_a?(String)
1122
- assoc_bt[:fk] = [assoc_bt[:fk], fk[1]] unless fk[1] == assoc_bt[:fk]
1123
- elsif assoc_bt[:fk].exclude?(fk[1])
1124
- assoc_bt[:fk] << fk[1]
1137
+ if assoc_hm[:fk].is_a?(String)
1138
+ assoc_hm[:fk] = [assoc_hm[:fk], fk[1]] unless fk[1] == assoc_hm[:fk]
1139
+ elsif assoc_hm[:fk].exclude?(fk[1])
1140
+ assoc_hm[:fk] << fk[1]
1125
1141
  end
1126
1142
  assoc_hm[:alternate_name] = "#{assoc_hm[:alternate_name]}_#{bt_assoc_name}" unless assoc_hm[:alternate_name] == bt_assoc_name
1127
1143
  assoc_hm[:inverse] = assoc_bt
@@ -71,7 +71,8 @@ module Brick
71
71
  keys = if fk_name.is_a?(Array) && pk.is_a?(Array) # Composite keys?
72
72
  fk_name.zip(pk.map { |pk_part| "#{obj_name}.#{pk_part}" })
73
73
  else
74
- [[fk_name, "#{obj_name}.#{pk}"]]
74
+ pk = pk.each_with_object([]) { |pk_part, s| s << "#{obj_name}.#{pk_part}" }
75
+ [[fk_name, "#{pk.length == 1 ? pk.first : pk.inspect}"]]
75
76
  end
76
77
  keys << [hm_assoc.inverse_of.foreign_type, "#{hm_assoc.active_record.name}"] if hm_assoc.options.key?(:as)
77
78
  keys.map { |x| "#{x.first}: #{x.last}"}.join(', ')
@@ -82,7 +83,7 @@ module Brick
82
83
  return _brick_find_template(*args, **options) unless @_brick_model
83
84
 
84
85
  model_name = @_brick_model.name
85
- pk = @_brick_model.primary_key
86
+ pk = @_brick_model._brick_primary_key(::Brick.relations[model_name])
86
87
  obj_name = model_name.underscore
87
88
  table_name = model_name.pluralize.underscore
88
89
  template_link = nil
@@ -283,7 +284,7 @@ function changeout(href, param, value) {
283
284
  inline = case args.first
284
285
  when 'index'
285
286
  obj_pk = if pk&.is_a?(Array) # Composite primary key?
286
- "[#{pk.map { |pk_part| "#{obj_name}.#{pk_part}" }.join(', ')}]"
287
+ "[#{pk.map { |pk_part| "#{obj_name}.#{pk_part}" }.join(', ')}]" unless pk.empty?
287
288
  elsif pk
288
289
  "#{obj_name}.#{pk}"
289
290
  end
@@ -385,9 +386,9 @@ function changeout(href, param, value) {
385
386
 
386
387
  <% if @_brick_params&.present? %><h3>where <%= @_brick_params.each_with_object([]) { |v, s| s << \"#\{v.first\} = #\{v.last.inspect\}\" }.join(', ') %></h3><% end %>
387
388
  <table id=\"#{table_name}\">
388
- <thead><tr>#{'<th></th>' if pk}
389
+ <thead><tr>#{'<th></th>' if pk.present?}
389
390
  <% @#{table_name}.columns.map(&:name).each do |col| %>
390
- <% next if col == '#{pk}' || ::Brick.config.metadata_columns.include?(col) || poly_cols.include?(col) %>
391
+ <% next if #{pk.inspect}.include?(col) || ::Brick.config.metadata_columns.include?(col) || poly_cols.include?(col) %>
391
392
  <th>
392
393
  <% if (bt = bts[col]) %>
393
394
  BT <%
@@ -408,7 +409,7 @@ function changeout(href, param, value) {
408
409
  <tr>#{"
409
410
  <td><%= link_to '⇛', #{obj_name}_path(#{obj_pk}), { class: 'big-arrow' } %></td>" if obj_pk}
410
411
  <% #{obj_name}.attributes.each do |k, val| %>
411
- <% next if k == '#{pk}' || ::Brick.config.metadata_columns.include?(k) || poly_cols.include?(k) || k.start_with?('_brfk_') || (k.start_with?('_br_') && (k.length == 63 || k.end_with?('_ct'))) %>
412
+ <% next if #{obj_pk.inspect}.include?(k) || ::Brick.config.metadata_columns.include?(k) || poly_cols.include?(k) || k.start_with?('_brfk_') || (k.start_with?('_br_') && (k.length == 63 || k.end_with?('_ct'))) %>
412
413
  <td>
413
414
  <% if (bt = bts[k]) %>
414
415
  <%# binding.pry # Postgres column names are limited to 63 characters %>
@@ -456,7 +457,7 @@ function changeout(href, param, value) {
456
457
  @#{obj_name}.attributes.each do |k, val| %>
457
458
  <tr>
458
459
  <%# %%% Accommodate composite keys %>
459
- <% next if k == '#{pk}' || ::Brick.config.metadata_columns.include?(k) %>
460
+ <% next if #{pk}.include?(k) || ::Brick.config.metadata_columns.include?(k) %>
460
461
  <th class=\"show-field\">
461
462
  <% has_fields = true
462
463
  if (bt = bts[k])
@@ -464,26 +465,31 @@ function changeout(href, param, value) {
464
465
  bt_name = bt[1].map { |x| x.first.name }.join('/')
465
466
  # %%% Only do this if the user has permissions to edit this bt field
466
467
  if bt[2] # Polymorphic?
467
- poly_class_name = @#{obj_name}.send(\"#\{bt.first\}_type\")
468
+ poly_class_name = orig_poly_name = @#{obj_name}.send(\"#\{bt.first\}_type\")
468
469
  bt_pair = nil
469
470
  loop do
470
471
  bt_pair = bt[1].find { |pair| pair.first.name == poly_class_name }
471
472
  # Acxommodate any valid STI by going up the chain of inheritance
472
473
  break unless bt_pair.nil? && poly_class_name = ::Brick.existing_stis[poly_class_name]
473
474
  end
475
+ puts \"*** Might be missing an STI class called #\{orig_poly_name\} whose base class should have this:
476
+ *** has_many :#{table_name}, as: :#\{bt.first\}
477
+ *** Can probably auto-configure everything using these lines in an initialiser:
478
+ *** Brick.sti_namespace_prefixes = { '::#\{orig_poly_name\}' => 'SomeParentModel' }
479
+ *** Brick.polymorphics = { '#{table_name}.#\{bt.first\}' => ['SomeParentModel'] }\" if bt_pair.nil?
474
480
  # descrips = @_brick_bt_descrip[bt.first][bt_class]
475
481
  poly_id = @#{obj_name}.send(\"#\{bt.first\}_id\")
476
482
  # bt_class.order(obj_pk = bt_class.primary_key).each { |obj| option_detail << [obj.brick_descrip(nil, obj_pk), obj.send(obj_pk)] }
477
483
  else # No polymorphism, so just get the first one
478
484
  bt_pair = bt[1].first
479
485
  end
480
- bt_class = bt_pair.first
486
+ bt_class = bt_pair&.first
481
487
  if bt.length < 4
482
488
  bt << (option_detail = [[\"(No #\{bt_name\} chosen)\", '^^^brick_NULL^^^']])
483
489
  # %%% Accommodate composite keys for obj.pk at the end here
484
- bt_class.order(obj_pk = bt_class.primary_key).each { |obj| option_detail << [obj.brick_descrip(nil, obj_pk), obj.send(obj_pk)] }
490
+ bt_class&.order(obj_pk = bt_class.primary_key)&.each { |obj| option_detail << [obj.brick_descrip(nil, obj_pk), obj.send(obj_pk)] }
485
491
  end %>
486
- BT <%= bt_class.bt_link(bt.first) %>
492
+ BT <%= bt_class&.bt_link(bt.first) || orig_poly_name %>
487
493
  <% else %>
488
494
  <%= k %>
489
495
  <% end %>
@@ -493,7 +499,7 @@ function changeout(href, param, value) {
493
499
  html_options = { prompt: \"Select #\{bt_name\}\" }
494
500
  html_options[:class] = 'dimmed' unless val %>
495
501
  <%= f.select k.to_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options %>
496
- <%= bt_obj = bt_class.find_by(bt_pair[1] => val); link_to('⇛', send(\"#\{bt_class.base_class.name.underscore\}_path\".to_sym, bt_obj.send(bt_class.primary_key.to_sym)), { class: 'show-arrow' }) if bt_obj %>
502
+ <%= bt_obj = bt_class&.find_by(bt_pair[1] => val); link_to('⇛', send(\"#\{bt_class.base_class.name.underscore\}_path\".to_sym, bt_obj.send(bt_class.primary_key.to_sym)), { class: 'show-arrow' }) if bt_obj %>
497
503
  <% else case #{model_name}.column_for_attribute(k).type
498
504
  when :string, :text %>
499
505
  <% if is_bcrypt?(val) # || .readonly? %>
@@ -213,7 +213,7 @@ module Brick
213
213
  puts "X3"
214
214
  super(key, ::Brick::JoinArray.new.replace([current, value]))
215
215
  when ::Brick::JoinArray # Concatenate new stuff onto any existing JoinArray
216
- current.set_matching(value, nil)
216
+ current.set_matching(value, nil) if value
217
217
  when ::Brick::JoinHash # Graduate an existing hash into being in an array if things are dissimilar
218
218
  super(key, ::Brick::JoinArray.new.replace([current, value]))
219
219
  value
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 27
8
+ TINY = 28
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -325,9 +325,9 @@ module Brick
325
325
  You might be missing an STI namespace prefix entry for these tables: #{missing_stis.keys.join(', ')}.
326
326
  In config/initializers/brick.rb appropriate entries would look something like:
327
327
  Brick.sti_namespace_prefixes = {"
328
- puts missing_stis.map { |_k, missing_sti| "\n '::#{missing_sti}' => 'YourParentModel'" }.join(',')
328
+ puts missing_stis.map { |_k, missing_sti| "\n '::#{missing_sti}' => 'SomeParentModel'" }.join(',')
329
329
  puts " }
330
- (Just trade out YourParentModel with some more appropriate one.)"
330
+ (Just trade out SomeParentModel with some more appropriate one.)"
331
331
  end
332
332
  end
333
333
  @_additional_references_loaded = true
@@ -451,7 +451,7 @@ ActiveSupport.on_load(:active_record) do
451
451
  relation = clone # spawn
452
452
  relation.select_values = column_names
453
453
  result = if klass.connection.class.name.end_with?('::PostgreSQLAdapter')
454
- rslt = klass.connection.execute(relation.arel.to_sql)
454
+ rslt = klass.execute_sql(relation.arel.to_sql)
455
455
  rslt.type_map =
456
456
  @type_map ||= proc do
457
457
  # This aliasing avoids the warning:
@@ -113,24 +113,24 @@ module Brick
113
113
  # # #{resembles_fks.join(', ')}"
114
114
  end
115
115
 
116
- poly = case (possible_polymorphics = possible_polymorphics.values.flatten).length
116
+ poly = case (possible_polymorphics = possible_polymorphics.values.flatten.map { |poss_poly| "#{poss_poly} => nil"}).length
117
117
  when 0
118
118
  " like this:
119
- # Brick.polymorphics = [
120
- # 'comments.commentable',
121
- # 'images.imageable'
122
- # ]"
119
+ # Brick.polymorphics = {
120
+ # 'comments.commentable' => nil,
121
+ # 'images.imageable' => nil
122
+ # }"
123
123
  when 1
124
124
  ".
125
125
  # # Here is a possible polymorphic association that has been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
126
- # Brick.polymorphics = [#{possible_additional_references.first}]"
126
+ # Brick.polymorphics = { #{possible_additional_references.first} }"
127
127
 
128
128
  else
129
129
  ".
130
130
  # # Here are possible polymorphic associations that have been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
131
- # Brick.polymorphics = [
131
+ # Brick.polymorphics = {
132
132
  # #{possible_polymorphics.join(",\n# ")}
133
- # ]"
133
+ # }"
134
134
  end
135
135
 
136
136
  create_file(filename, "# frozen_string_literal: true
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.27
4
+ version: 1.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-22 00:00:00.000000000 Z
11
+ date: 2022-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord