brick 1.0.90 → 1.0.91

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: eca72d418715811a100a44a45b3cd054ca511ed280f1d1a6f344ddaa972c220c
4
- data.tar.gz: d712ebb5dedf75da99d8d8720f4b89e29ea2e96b498b4a59540811f5e087231c
3
+ metadata.gz: 81eaa518a99452286bdaf1e5ed33b83962ede9f9c6509f0b472fd0fe19a8eceb
4
+ data.tar.gz: 06f5653ce40eb6ee1568b380cf3063073ac7735add8aab6c5873a343e8018a70
5
5
  SHA512:
6
- metadata.gz: 1b3d3941f4905b7a3ce1489a6f018d958331bd4c2970a5ba5034eb0fb81683febdc8a93562be5a1505afe6d6479fb1ed068a0f21d6ea80f24460e9e9267b8ea3
7
- data.tar.gz: c3f61b68cd2ca5790f93b82010909f65913ccecb46df24786c83db362241092824db66833b72f03708560f23b7e87f64f12b180d8e4fb9ababba32bdb9b3f9df
6
+ metadata.gz: 7e0a678885c927a7a80c8758d265c2ff351f67ea44e8e1b2c128e123df441f4f72a62f775b9785615eeacbdbff99427e9d1590890bdffd06165ae7b2339fe1af
7
+ data.tar.gz: 7bd3e424225e435bab4517fb14aeaa3ca128041a746aaf413ecdb17a771444c3413f058ff28cc5e303d074fdd7cc7d21ff66f842667c14226d1849e96d4b3a98
@@ -309,9 +309,15 @@ module ActiveRecord
309
309
  def self._brick_calculate_bts_hms(translations, join_array)
310
310
  # Add any custom columns
311
311
  ::Brick.config.custom_columns&.fetch(table_name, nil)&.each do |k, cc|
312
+ if cc.is_a?(Array)
313
+ fk_col = cc.last unless cc.last.blank?
314
+ cc = cc.first
315
+ else
316
+ fk_col = true
317
+ end
312
318
  # false = not polymorphic, and true = yes -- please emit_dsl
313
319
  pieces, my_dsl = brick_parse_dsl(join_array, [], translations, false, cc, true)
314
- _br_cust_cols[k] = [pieces, my_dsl]
320
+ _br_cust_cols[k] = [pieces, my_dsl, fk_col]
315
321
  end
316
322
  bts, hms, associatives = ::Brick.get_bts_and_hms(self)
317
323
  bts.each do |_k, bt|
@@ -557,6 +563,10 @@ module ActiveRecord
557
563
  next
558
564
  end
559
565
 
566
+ key_klass = nil
567
+ key_tbl_name = nil
568
+ dest_pk = nil
569
+ key_alias = nil
560
570
  cc.first.each do |cc_part|
561
571
  dest_klass = cc_part[0..-2].inject(klass) { |kl, cc_part_term| kl.reflect_on_association(cc_part_term).klass }
562
572
  tbl_name = (field_tbl_names[k][cc_part.last] ||= shift_or_first(chains[dest_klass])).split('.').last
@@ -569,10 +579,29 @@ module ActiveRecord
569
579
  used_col_aliases.key?(col_alias)
570
580
  cc_part_idx -= 1
571
581
  end
582
+ used_col_aliases[col_alias] = nil
583
+ # Set up custom column links by preparing key_klass and key_alias
584
+ # (If there are multiple different tables referenced in the DSL, we end up creating a link to the last one)
585
+ if cc[2] && (dest_pk = dest_klass.primary_key)
586
+ key_klass = dest_klass
587
+ key_tbl_name = tbl_name
588
+ cc_part_idx = cc_part.length - 1
589
+ while cc_part_idx > 0 &&
590
+ (key_alias = "br_cc_#{k}__#{(cc_part[cc_part_idx..-2] + [dest_pk]).map(&:to_s).join('__')}") &&
591
+ key_alias != col_alias && # We break out if this key alias does exactly match the col_alias
592
+ used_col_aliases.key?(key_alias)
593
+ cc_part_idx -= 1
594
+ end
595
+ end
572
596
  selects << "#{tbl_name}.#{cc_part.last} AS #{col_alias}"
573
597
  cc_part << col_alias
574
- used_col_aliases[col_alias] = nil
575
598
  end
599
+ # Add a key column unless we've already got it
600
+ if key_alias && !used_col_aliases.key?(key_alias)
601
+ selects << "#{key_tbl_name}.#{dest_pk} AS #{key_alias}"
602
+ used_col_aliases[key_alias] = nil
603
+ end
604
+ cc[2] = key_alias ? [key_klass, key_alias] : nil
576
605
  end
577
606
 
578
607
  klass._br_bt_descrip.each do |v|
@@ -1167,7 +1196,7 @@ class Object
1167
1196
  if (base_model = ::Brick.sti_models[full_model_name]&.fetch(:base, nil) || ::Brick.existing_stis[full_model_name]&.constantize)
1168
1197
  is_sti = true
1169
1198
  else
1170
- base_model = ::Brick.config.models_inherit_from || ActiveRecord::Base
1199
+ base_model = ::Brick.config.models_inherit_from
1171
1200
  end
1172
1201
  hmts = nil
1173
1202
  code = +"class #{full_name} < #{base_model.name}\n"
@@ -19,7 +19,12 @@ module Brick
19
19
  ::Brick.exclude_tables = app.config.brick.fetch(:exclude_tables, [])
20
20
 
21
21
  # Class for auto-generated models to inherit from
22
- ::Brick.models_inherit_from = app.config.brick.fetch(:models_inherit_from, ActiveRecord::Base)
22
+ ::Brick.models_inherit_from = app.config.brick.fetch(:models_inherit_from, nil) ||
23
+ begin
24
+ ::ApplicationRecord
25
+ rescue StandardError => ex
26
+ ::ActiveRecord::Base
27
+ end
23
28
 
24
29
  # When table names have specific prefixes, automatically place them in their own module with a table_name_prefix.
25
30
  ::Brick.table_name_prefixes = app.config.brick.fetch(:table_name_prefixes, [])
@@ -985,7 +990,12 @@ erDiagram
985
990
  %><%= display_value(col_type || col&.sql_type, val) %><%
986
991
  elsif cust_col
987
992
  data = cust_col.first.map { |cc_part| #{obj_name}.send(cc_part.last) }
988
- %><%= #{model_name}.brick_descrip(cust_col.last, data) %><%
993
+ cust_txt = #{model_name}.brick_descrip(cust_col[-2], data)
994
+ if (link_id = #{obj_name}.send(cust_col.last[1]) if cust_col.last)
995
+ %><%= link_to(cust_txt, send(\"#\{cust_col.last.first._brick_index(:singular)}_path\", link_id)) %><%
996
+ else
997
+ %><%= cust_txt %><%
998
+ end
989
999
  else # Bad column name!
990
1000
  %>?<%
991
1001
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 90
8
+ TINY = 91
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
@@ -139,7 +139,7 @@ module Brick
139
139
  # Settings for the Brick gem
140
140
  # (By default this auto-creates models, controllers, views, and routes on-the-fly.)
141
141
 
142
- if Object.const_defined?('Brick')
142
+ if ActiveRecord::Base.respond_to?(:brick_select)
143
143
  # Mode -- generally :on or :off, or only in :development. Also available is :diag_env which enables only
144
144
  # when the environment variable BRICK is set.
145
145
  Brick.mode = :development
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.90
4
+ version: 1.0.91
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-11-04 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord