brick 1.0.49 → 1.0.50

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: 8b42f1ad45e6dc942ed2e875d39318f8705f9a467c0cb31f267a71a01053bfd4
4
- data.tar.gz: 1e8f0cd1c374c5d75be4e4f1a8b659dd32b46f991c85cce4d234a6949d017e4b
3
+ metadata.gz: d5f5d009df0d4a7ce06a5dec8986d2664671e8b151f7493e5ce3f8f690ec7028
4
+ data.tar.gz: 974e86906775728e0ff0c7022cfbd87578b7c3013a8f9a5fe0db2243dcad9bf1
5
5
  SHA512:
6
- metadata.gz: 437d415278f01a2ffced31687f77324c21416e6e7ef395d6a5d3db5a1853ccfb301c01716747ba4427417164a1200100205e7b7c75443bef83f1050f01683dda
7
- data.tar.gz: d42367f291f2900876c5263aab30280f7b5b3d9f205c4199349b9e24d35326b5457e1db8fd0d39a512f59af9691bbe44e29dd05d3384d5a0013c05ffe6447d8c
6
+ metadata.gz: 0f652cf44f9d18eca35304d1660ed3967d39c60dff42bcc05043607fada17d427308b7052a4b474c71d8a65462f86970838771471b6f1dd7a89accabc31ddd27
7
+ data.tar.gz: 386030a8bd3c603264ed9f534e1188eb5710fe67777ffc9634a9c318e8bac4153d2716bffbf9c34a7ff63999c3af39b2fa6db3b324abc5093467a33b144b41b8
@@ -221,13 +221,19 @@ module ActiveRecord
221
221
  template
222
222
  end
223
223
 
224
- # belongs_to DSL descriptions
225
- def self._br_bt_descrip
226
- @_br_bt_descrip ||= {}
227
- end
228
- # has_many count definitions
229
- def self._br_hm_counts
230
- @_br_hm_counts ||= {}
224
+ class << self
225
+ # belongs_to DSL descriptions
226
+ def _br_bt_descrip
227
+ @_br_bt_descrip ||= {}
228
+ end
229
+ # has_many count definitions
230
+ def _br_hm_counts
231
+ @_br_hm_counts ||= {}
232
+ end
233
+ # has_many :through associative tables
234
+ def _br_associatives
235
+ @_br_associatives ||= {}
236
+ end
231
237
  end
232
238
 
233
239
  # Search for BT, HM, and HMT DSL stuff
@@ -374,7 +380,7 @@ module ActiveRecord
374
380
 
375
381
  case (ks = k.split('.')).length
376
382
  when 1
377
- next unless klass._brick_get_fks.include?(k)
383
+ next unless klass.column_names.any?(k) || klass._brick_get_fks.include?(k)
378
384
  when 2
379
385
  assoc_name = ks.first.to_sym
380
386
  # Make sure it's a good association name and that the model has that column name
@@ -408,6 +414,7 @@ module ActiveRecord
408
414
  chains = rel_dupe._brick_chains
409
415
  id_for_tables = Hash.new { |h, k| h[k] = [] }
410
416
  field_tbl_names = Hash.new { |h, k| h[k] = {} }
417
+ used_col_aliases = {} # Used to make sure there is not a name clash
411
418
  bt_columns = klass._br_bt_descrip.each_with_object([]) do |v, s|
412
419
  v.last.each do |k1, v1| # k1 is class, v1 is array of columns to snag
413
420
  next if chains[k1].nil?
@@ -419,7 +426,12 @@ module ActiveRecord
419
426
 
420
427
  # Postgres can not use DISTINCT with any columns that are XML, so for any of those just convert to text
421
428
  is_xml = is_distinct && Brick.relations[sel_col.first.table_name]&.[](:cols)&.[](sel_col.last)&.first&.start_with?('xml')
422
- selects << "\"#{field_tbl_name}\".\"#{sel_col.last}\"#{'::text' if is_xml} AS \"#{(col_alias = "_brfk_#{v.first}__#{sel_col.last}")}\""
429
+ # If it's not unique then also include the belongs_to association name before the column name
430
+ if used_col_aliases.key?(col_alias = "_brfk_#{v.first}__#{sel_col.last}")
431
+ col_alias = "_brfk_#{v.first}__#{v1[idx][-2..-1].map(&:to_s).join('__')}"
432
+ end
433
+ selects << "\"#{field_tbl_name}\".\"#{sel_col.last}\"#{'::text' if is_xml} AS \"#{col_alias}\""
434
+ used_col_aliases[col_alias] = nil
423
435
  v1[idx] << col_alias
424
436
  end
425
437
 
@@ -447,8 +459,7 @@ module ActiveRecord
447
459
  klass._br_hm_counts.each do |k, hm|
448
460
  associative = nil
449
461
  count_column = if hm.options[:through]
450
- fk_col = (associative = associatives[hm.name])&.foreign_key
451
- hm.foreign_key if fk_col
462
+ hm.foreign_key if (fk_col = (associative = klass._br_associatives&.[](hm.name))&.foreign_key)
452
463
  else
453
464
  fk_col = hm.foreign_key
454
465
  poly_type = hm.inverse_of.foreign_type if hm.options.key?(:as)
@@ -502,7 +513,7 @@ JOIN (SELECT #{selects.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}
502
513
  end
503
514
 
504
515
  private
505
-
516
+
506
517
  def shift_or_first(ary)
507
518
  ary.length > 1 ? ary.shift : ary.first
508
519
  end
@@ -104,7 +104,7 @@ module Brick
104
104
  path_obj_name = model_name.underscore.tr('/', '_')
105
105
  table_name = obj_name.pluralize
106
106
  template_link = nil
107
- bts, hms, associatives = ::Brick.get_bts_and_hms(@_brick_model) # This gets BT and HM and also has_many :through (HMT)
107
+ bts, hms = ::Brick.get_bts_and_hms(@_brick_model) # This gets BT and HM and also has_many :through (HMT)
108
108
  hms_columns = [] # Used for 'index'
109
109
  skip_klass_hms = ::Brick.config.skip_index_hms[model_name] || {}
110
110
  hms_headers = hms.each_with_object([]) do |hm, s|
@@ -112,7 +112,7 @@ module Brick
112
112
  "H#{hm_assoc.macro == :has_one ? 'O' : 'M'}#{'T' if hm_assoc.options[:through]}",
113
113
  (assoc_name = hm.first)]
114
114
  hm_fk_name = if hm_assoc.options[:through]
115
- associative = associatives[hm.first]
115
+ associative = @_brick_model._br_associatives[hm.first]
116
116
  tbl_nm = if hm_assoc.options[:source]
117
117
  associative.klass.reflect_on_association(hm_assoc.options[:source]).inverse_of&.name
118
118
  else
@@ -166,12 +166,12 @@ module Brick
166
166
  # %%% If we are not auto-creating controllers (or routes) then omit by default, and if enabled anyway, such as in a development
167
167
  # environment or whatever, then get either the controllers or routes list instead
168
168
  apartment_default_schema = ::Brick.apartment_multitenant && Apartment.default_schema
169
- table_options = (::Brick.relations.keys - ::Brick.config.exclude_tables).map do |tbl|
169
+ table_options = (::Brick.relations.keys - ::Brick.config.exclude_tables).each_with_object({}) do |tbl, s|
170
170
  if (tbl_parts = tbl.split('.')).first == apartment_default_schema
171
171
  tbl = tbl_parts.last
172
172
  end
173
- tbl
174
- end.sort.each_with_object(+'') do |v, s|
173
+ s[tbl] = nil
174
+ end.keys.sort.each_with_object(+'') do |v, s|
175
175
  s << "<option value=\"#{v.underscore.gsub('.', '/').pluralize}\">#{v}</option>"
176
176
  end.html_safe
177
177
  table_options << '<option value="brick_orphans">(Orphans)</option>'.html_safe if is_orphans
@@ -562,7 +562,7 @@ if (headerTop) {
562
562
  col_order << col_name
563
563
  %><th<%= \" title=\\\"#\{col.comment}\\\"\".html_safe if col.respond_to?(:comment) && !col.comment.blank? %><%
564
564
  if (bt = bts[col_name]) %>
565
- <%= \" x-order=\\\"#\{bt.first}\\\"\".html_safe if true # Currently we always allow click to sort
565
+ <%= \" x-order=\\\"#\{bt.first}\\\"\".html_safe unless bt[2] # Allow sorting any BT except polymorphics
566
566
  %>>BT <%
567
567
  bt[1].each do |bt_pair| %><%=
568
568
  bt_pair.first.bt_link(bt.first) %> <%
@@ -807,7 +807,9 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
807
807
  # %%% Create a smart javascript routine which can do this client-side %>
808
808
  [... document.getElementsByTagName(\"TH\")].forEach(function (th) {
809
809
  th.addEventListener(\"click\", function (e) {
810
- location.href = changeout(location.href, \"_brick_order\", this.getAttribute(\"x-order\"));
810
+ var xOrder;
811
+ if (xOrder = this.getAttribute(\"x-order\"))
812
+ location.href = changeout(location.href, \"_brick_order\", xOrder);
811
813
  });
812
814
  });
813
815
  document.querySelectorAll(\"input, select\").forEach(function (inp) {
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 49
8
+ TINY = 50
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
@@ -172,14 +172,14 @@ module Brick
172
172
  # Mark has_manys that go to an associative ("join") table so that they are skipped in the UI,
173
173
  # as well as any possible polymorphic associations
174
174
  skip_hms = {}
175
- associatives = hms.each_with_object({}) do |hmt, s|
175
+ hms.each do |hmt|
176
176
  if (through = hmt.last.options[:through])
177
177
  skip_hms[through] = nil # if hms[through]
178
178
  # binding.pry if !hms[through]
179
179
  # End up with a hash of HMT names pointing to join-table associations
180
180
  # Last part was: hmt.last.name
181
181
  # Changed up because looking for: hms[:issue_issue_duplicates]
182
- s[hmt.first] = hms[through] # || hms["#{(opt = hmt.last.options)[:through].to_s.singularize}_#{opt[:source].to_s.pluralize}".to_sym]
182
+ model._br_associatives[hmt.first] = hms[through] # || hms["#{(opt = hmt.last.options)[:through].to_s.singularize}_#{opt[:source].to_s.pluralize}".to_sym]
183
183
  elsif hmt.last.inverse_of.nil?
184
184
  puts "SKIPPING #{hmt.last.name.inspect}"
185
185
  # %%% If we don't do this then below associative.name will find that associative is nil
@@ -187,7 +187,7 @@ module Brick
187
187
  end
188
188
  end
189
189
  skip_hms.each { |k, _v| hms.delete(k) }
190
- [bts, hms, associatives]
190
+ [bts, hms]
191
191
  end
192
192
 
193
193
  # Switches Brick auto-models on or off, for all threads
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.49
4
+ version: 1.0.50
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-07-24 00:00:00.000000000 Z
11
+ date: 2022-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord