brick 1.0.129 → 1.0.130

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: 3b46bf80d393c0d6e4ffea3e8bfc1fbc03dc667902077efc9a887c8ab046a817
4
- data.tar.gz: 927828e46dfd9ae6b7c14aced0f814bbc1d876e5af14aa872a13d2c13af85083
3
+ metadata.gz: 902948e0d502bc9c1b604f3e99b975ab8c7d42c378888280d84dac6aef2aa7d0
4
+ data.tar.gz: 82988754dcae3ccc67eb5997531b3fa218ecf364f076ecf221fac201412baff0
5
5
  SHA512:
6
- metadata.gz: 49073fb48479c8df6805a35632ef321efa3144556feb1e2da701044ce110aa6cfcb8ced12186408929b8c3d6280ca6e393e886ba54eea87f0a622a58f9216e8e
7
- data.tar.gz: eaccf857c54a108c764e786b5e8abd0f54ff5abbcadec558138dc947a5d7e3015fc1a5510a311301947cee815d086018e535a15958357abd3463ab59ee375908
6
+ metadata.gz: 780184ebc02c020389bc2239e115e885df056fa6895ed32bd35b5315f2e55f86deb679f2966e7290118bc54f4d50478b4240d7d77470d27a5902af22948d83f1
7
+ data.tar.gz: 39c37a9db2c7c392209491e1609f8ab4c2b64d27371452b60310d326bd462b5e653196697d0faf8f4bf801793400e073bf73f2ed72a38e9c66bd9b8e98d1e778
@@ -148,7 +148,8 @@ module ActiveRecord
148
148
  translations[parts[0..-2].join('.')] = klass
149
149
  end
150
150
  if klass&.column_names.exclude?(parts.last) &&
151
- (klass = (orig_class = klass).reflect_on_association(possible_dsl = parts.pop.to_sym)&.klass)
151
+ (klass = (orig_class = klass).reflect_on_association(possible_dsl = parts.last&.to_sym)&.klass)
152
+ parts.pop
152
153
  if prefix.empty? # Custom columns start with an empty prefix
153
154
  prefix << parts.shift until parts.empty?
154
155
  end
@@ -162,6 +163,7 @@ module ActiveRecord
162
163
  if emit_dsl
163
164
  dsl3 << "[#{prefix[1..-1].map { |p| "#{p.to_s}." }.join if prefix.length > 1}#{bracket_name}]"
164
165
  end
166
+ parts[-1] = column_names.first if parts[-1].nil? # No primary key to be found? Grab something to display!
165
167
  members << parts
166
168
  end
167
169
  end
@@ -231,7 +233,8 @@ module ActiveRecord
231
233
  if this_obj.is_a?(ActiveRecord::Base) && (obj_descrip = this_obj.class.brick_descrip(this_obj))
232
234
  this_obj = obj_descrip
233
235
  end
234
- if this_obj.is_a?(ActiveStorage::Filename) && this_obj.instance_variable_get(:@filename).nil?
236
+ if Object.const_defined?('ActiveStorage') && this_obj.is_a?(::ActiveStorage::Filename) &&
237
+ this_obj.instance_variable_get(:@filename).nil?
235
238
  this_obj.instance_variable_set(:@filename, '')
236
239
  end
237
240
  this_obj&.to_s || ''
@@ -741,12 +744,20 @@ module ActiveRecord
741
744
  end
742
745
  else
743
746
  fk_col = (inv = hm.inverse_of)&.foreign_key || hm.foreign_key
744
- poly_type = inv.foreign_type if hm.options.key?(:as)
747
+ # %%% Might only need hm.type and not the first part :)
748
+ poly_type = inv&.foreign_type || hm.type if hm.options.key?(:as)
745
749
  pk = hm.klass.primary_key
746
750
  (pk.is_a?(Array) ? pk.first : pk) || '*'
747
751
  end
748
752
  next unless count_column # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
749
753
 
754
+ pri_tbl = hm.active_record
755
+ pri_key = hm.options[:primary_key] || pri_tbl.primary_key
756
+ unless hm.klass.column_names.include?(pri_key)
757
+ nix << k
758
+ next
759
+ end
760
+
750
761
  tbl_alias = if is_mysql
751
762
  "`b_r_#{hm.name}`"
752
763
  elsif is_postgres
@@ -754,7 +765,6 @@ module ActiveRecord
754
765
  else
755
766
  "b_r_#{hm.name}"
756
767
  end
757
- pri_tbl = hm.active_record
758
768
  pri_tbl_name = is_mysql ? "`#{pri_tbl.table_name}`" : "\"#{pri_tbl.table_name.gsub('.', '"."')}\""
759
769
  pri_tbl_name = if is_mysql
760
770
  "`#{pri_tbl.table_name}`"
@@ -765,10 +775,10 @@ module ActiveRecord
765
775
  end
766
776
  on_clause = []
767
777
  hm_selects = if fk_col.is_a?(Array) # Composite key?
768
- fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl_name}.#{pri_tbl.primary_key[idx]}" }
778
+ fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl_name}.#{pri_key[idx]}" }
769
779
  fk_col.dup
770
780
  else
771
- on_clause << "#{tbl_alias}.#{fk_col} = #{pri_tbl_name}.#{pri_tbl.primary_key}"
781
+ on_clause << "#{tbl_alias}.#{fk_col} = #{pri_tbl_name}.#{pri_key}"
772
782
  [fk_col]
773
783
  end
774
784
  if poly_type
@@ -1869,7 +1879,7 @@ class Object
1869
1879
  # Convert any Filename objects with nil into an empty string so that #encode can be called on them
1870
1880
  new_obj.serializable_hash.each do |k, v|
1871
1881
  new_obj.send("#{k}=", ActiveStorage::Filename.new('')) if v.is_a?(ActiveStorage::Filename) && !v.instance_variable_get(:@filename)
1872
- end
1882
+ end if Object.const_defined?('ActiveStorage')
1873
1883
  end
1874
1884
  instance_variable_set("@#{singular_table_name}".to_sym, new_obj)
1875
1885
  end
@@ -2441,7 +2451,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
2441
2451
  singular = rel_name.last
2442
2452
  end
2443
2453
  name_parts = if (tnp = ::Brick.config.table_name_prefixes
2444
- .find { |k1, _v1| singular.start_with?(k1) && singular.length > k1.length }
2454
+ &.find { |k1, _v1| singular.start_with?(k1) && singular.length > k1.length }
2445
2455
  ).present?
2446
2456
  v[:auto_prefixed_schema] = tnp.first
2447
2457
  v[:resource] = rel_name.last[(tnp_length = tnp.first.length)..-1]
@@ -652,7 +652,9 @@ window.addEventListener(\"popstate\", linkSchemas);
652
652
  else
653
653
  hm_assoc.active_record.name
654
654
  end
655
- keys << [hm_assoc.inverse_of.foreign_type, poly_type]
655
+ # %%% Might only need hm_assoc.type and not the first part :)
656
+ type_col = hm_assoc.inverse_of&.foreign_type || hm_assoc.type
657
+ keys << [type_col, poly_type]
656
658
  end
657
659
  keys.to_h
658
660
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 129
8
+ TINY = 130
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
@@ -1661,7 +1661,8 @@ module ActiveRecord
1661
1661
  relation.brick_links[link_path] = if child.table.is_a?(Arel::Nodes::TableAlias)
1662
1662
  child.table.right
1663
1663
  else
1664
- result.first&.left&.table_alias || child.table_name
1664
+ # Was: result.first&.left&.table_alias || child.table_name
1665
+ child.table.table_alias || child.table_name
1665
1666
  end
1666
1667
  end
1667
1668
  result
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.129
4
+ version: 1.0.130
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-11 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord