brick 1.0.78 → 1.0.79
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +23 -15
- data/lib/brick/frameworks/rails/engine.rb +18 -0
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +15 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eedc546e7e9693459cf228ee376650cdf53c0325e55d50ef24bbf46d421f8738
|
4
|
+
data.tar.gz: c4feda4b5db8334363d05f3418dc172f0dbf408c21192222008a5b9a174ae448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c9713099c057b9c9041121576a4f38d5949213926a47d597f88f4a9021ce14cd3df2a30c14b8b929b92ba4549ec4492bdfd8de13cb0a4f710e911c00eab67b6
|
7
|
+
data.tar.gz: 27ca4aa6d40e165aaca5b09cf5b2ce97737b26adc8424b1d25d81b9813100679e9e06a61279c4fd8b96d750a89a4c4cb8eafbfe2d425a4d4c6868644820f297d
|
data/lib/brick/extensions.rb
CHANGED
@@ -614,15 +614,16 @@ module ActiveRecord
|
|
614
614
|
count_column = if hm.options[:through]
|
615
615
|
# Build the chain of JOINs going to the final destination HMT table
|
616
616
|
# (Usually just one JOIN, but could be many.)
|
617
|
-
|
617
|
+
hmt_assoc = hm
|
618
|
+
x = []
|
618
619
|
x.unshift(hmt_assoc) while hmt_assoc.options[:through] && (hmt_assoc = klass.reflect_on_association(hmt_assoc.options[:through]))
|
619
|
-
from_clause = +"#{x.first.
|
620
|
+
from_clause = +"#{x.first.table_name} br_t0"
|
620
621
|
fk_col = x.shift.foreign_key
|
621
622
|
link_back = [klass.primary_key] # %%% Inverse path back to the original object -- used to build out a link with a filter
|
622
623
|
idx = 0
|
623
624
|
bail_out = nil
|
624
|
-
x
|
625
|
-
from_clause << "\n LEFT OUTER JOIN #{a.
|
625
|
+
x.map do |a|
|
626
|
+
from_clause << "\n LEFT OUTER JOIN #{a.table_name} br_t#{idx += 1} "
|
626
627
|
from_clause << if (src_ref = a.source_reflection).macro == :belongs_to
|
627
628
|
"ON br_t#{idx}.id = br_t#{idx - 1}.#{a.foreign_key}"
|
628
629
|
elsif src_ref.options[:as]
|
@@ -637,18 +638,22 @@ module ActiveRecord
|
|
637
638
|
"ON br_t#{idx}.#{a.foreign_key} = br_t#{idx - 1}.id"
|
638
639
|
end
|
639
640
|
link_back.unshift(a.source_reflection.name)
|
640
|
-
[a.
|
641
|
+
[a.table_name, a.foreign_key, a.source_reflection.macro]
|
641
642
|
end
|
642
643
|
next if bail_out
|
643
|
-
# count_column is determined from the
|
644
|
-
if (src_ref =
|
645
|
-
"
|
644
|
+
# count_column is determined from the originating HMT member
|
645
|
+
if (src_ref = hm.source_reflection).nil?
|
646
|
+
puts "*** Warning: Could not determine destination model for this HMT association in model #{klass.name}:\n has_many :#{hm.name}, through: :#{hm.options[:through]}"
|
647
|
+
nix << k
|
648
|
+
bail_out = true
|
649
|
+
elsif src_ref.macro == :belongs_to # Traditional HMT using an associative table
|
650
|
+
"br_t#{idx}.#{hm.foreign_key}"
|
646
651
|
else # A HMT that goes HM -> HM, something like Categories -> Products -> LineItems
|
647
652
|
"br_t#{idx}.#{src_ref.active_record.primary_key}"
|
648
653
|
end
|
649
654
|
else
|
650
|
-
fk_col = hm.foreign_key
|
651
|
-
poly_type =
|
655
|
+
fk_col = (inv = hm.inverse_of)&.foreign_key || hm.foreign_key
|
656
|
+
poly_type = inv.foreign_type if hm.options.key?(:as)
|
652
657
|
pk = hm.klass.primary_key
|
653
658
|
(pk.is_a?(Array) ? pk.first : pk) || '*'
|
654
659
|
end
|
@@ -684,11 +689,11 @@ module ActiveRecord
|
|
684
689
|
end
|
685
690
|
unless from_clause
|
686
691
|
hm_table_name = if is_mysql
|
687
|
-
"`#{hm.
|
692
|
+
"`#{hm.table_name}`"
|
688
693
|
elsif is_postgres || is_mssql
|
689
|
-
"\"#{(hm.
|
694
|
+
"\"#{(hm.table_name).gsub('.', '"."')}\""
|
690
695
|
else
|
691
|
-
hm.
|
696
|
+
hm.table_name
|
692
697
|
end
|
693
698
|
end
|
694
699
|
group_bys = ::Brick.is_oracle || is_mssql ? selects : (1..selects.length).to_a
|
@@ -1383,7 +1388,7 @@ class Object
|
|
1383
1388
|
ordering = params['_brick_order']&.split(',')&.map(&:to_sym) || Object.send(:default_ordering, table_name, pk)
|
1384
1389
|
order_by, _ = model._brick_calculate_ordering(ordering, true) # Don't do the txt part
|
1385
1390
|
|
1386
|
-
@_brick_params = (ar_relation = model.all).brick_select(params, (selects = []),
|
1391
|
+
@_brick_params = (ar_relation = model.all).brick_select(params, (selects = []), order_by,
|
1387
1392
|
translations = {},
|
1388
1393
|
join_array = ::Brick::JoinArray.new)
|
1389
1394
|
# %%% Add custom HM count columns
|
@@ -1658,7 +1663,10 @@ module ActiveRecord::ConnectionHandling
|
|
1658
1663
|
# .default_schema are specified then we can work with non-tenanted models more appropriately
|
1659
1664
|
if (apartment = Object.const_defined?('Apartment')) &&
|
1660
1665
|
File.exist?(apartment_initializer = ::Rails.root.join('config/initializers/apartment.rb'))
|
1661
|
-
|
1666
|
+
unless @_apartment_loaded
|
1667
|
+
load apartment_initializer
|
1668
|
+
@_apartment_loaded = true
|
1669
|
+
end
|
1662
1670
|
apartment_excluded = Apartment.excluded_models
|
1663
1671
|
end
|
1664
1672
|
# Only for Postgres (Doesn't work in sqlite3 or MySQL)
|
@@ -813,6 +813,24 @@ erDiagram
|
|
813
813
|
hms_keys << (assoc_name = (assoc = hm.first).name.to_s)
|
814
814
|
"#{assoc_name.inspect} => [#{(assoc.options[:through] && !assoc.through_reflection).inspect}, #{assoc.klass.name}, #{hm[1].inspect}, #{hm[2].inspect}]"
|
815
815
|
end.join(', ')}}
|
816
|
+
# If the resource is missing, has the user simply created an inappropriately pluralised name for a table?
|
817
|
+
@#{table_name} ||= if dym_list = instance_variables.reject do |entry|
|
818
|
+
entry.to_s.start_with?('@_') ||
|
819
|
+
['@cache_hit', '@marked_for_same_origin_verification', '@view_renderer', '@view_flow', '@output_buffer', '@virtual_path'].include?(entry.to_s)
|
820
|
+
end
|
821
|
+
msg = \"Can't find resource \\\"#{table_name}\\\".\"
|
822
|
+
# Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
|
823
|
+
if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{table_name}')).present?
|
824
|
+
msg << \"\nIf you meant \\\"#\{found_dym = dym.first[1..-1]}\\\" then to avoid this message add this entry into inflections.rb:\n\"
|
825
|
+
msg << \" inflect.singular('#\{found_dym}', '#{obj_name}')\"
|
826
|
+
puts
|
827
|
+
puts \"WARNING: #\{msg}\"
|
828
|
+
puts
|
829
|
+
@#{table_name} = instance_variable_get(dym.first.to_sym)
|
830
|
+
else
|
831
|
+
raise ActiveRecord::RecordNotFound.new(msg)
|
832
|
+
end
|
833
|
+
end
|
816
834
|
col_keys = @#{table_name}.columns.each_with_object([]) do |col, s|
|
817
835
|
col_name = col.name
|
818
836
|
next if @_brick_incl&.exclude?(col_name) ||
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -179,13 +179,21 @@ module Brick
|
|
179
179
|
|
180
180
|
case a.macro
|
181
181
|
when :belongs_to
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
182
|
+
if a.polymorphic?
|
183
|
+
rel_poly_bt = relations[model.table_name][:fks].find { |_k, fk| fk[:assoc_name] == a.name.to_s }
|
184
|
+
if (primary_tables = rel_poly_bt&.last&.fetch(:inverse_table, [])).is_a?(Array)
|
185
|
+
models = primary_tables&.map { |table| table.singularize.camelize.constantize }
|
186
|
+
s.first[a.foreign_key] = [a.name, models, true]
|
187
|
+
else
|
188
|
+
# This will come up when using Devise invitable when invited_by_class_name is not
|
189
|
+
# specified because in that circumstance it adds a polymorphic :invited_by association,
|
190
|
+
# along with appropriate invited_by_type and invited_by_id columns.
|
191
|
+
puts "Missing any real indication as to which models \"has_many\" this polymorphic BT in model #{a.active_record.name}:"
|
192
|
+
puts " belongs_to :#{a.name}, polymorphic: true"
|
193
|
+
end
|
194
|
+
else
|
195
|
+
s.first[a.foreign_key] = [a.name, a.klass]
|
196
|
+
end
|
189
197
|
when :has_many, :has_one # This gets has_many as well as has_many :through
|
190
198
|
# %%% weed out ones that don't have an available model to reference
|
191
199
|
s.last[a.name] = a
|
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.
|
4
|
+
version: 1.0.79
|
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-10-
|
11
|
+
date: 2022-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|