brick 1.0.133 → 1.0.135
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 +41 -25
- data/lib/brick/frameworks/rails/engine.rb +3 -3
- data/lib/brick/version_number.rb +1 -1
- 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: 28451931f3f43343f010a14d83dd3ed2d4c2fc80e61234d5a96775dd16ff4f11
|
4
|
+
data.tar.gz: aeb7327ab42e4252d60ec92bc25d93c778fe15d83744b830aad7673d833c3e75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd85040932260d4a6d68eb46a0406cdbce355a3beb793fa8b56fca51228f4227c430b44fdb7852a8280894720220af4e6564775dfd474bbecf722749909779c3
|
7
|
+
data.tar.gz: f4f34d81eab0bf2922c888d618dd1e115f605132578627f7a16c39420d78a574bf63b2fd3e4d3a9278ceab52c4abba6bbc16bf1884dfd4183c0473c8943e42ca
|
data/lib/brick/extensions.rb
CHANGED
@@ -388,18 +388,42 @@ module ActiveRecord
|
|
388
388
|
order_by_txt&.<<("Arel.sql(#{ord_expr})")
|
389
389
|
s << Arel.sql(ord_expr)
|
390
390
|
else # Expecting only Symbol
|
391
|
-
|
392
|
-
|
393
|
-
|
391
|
+
ord_part = ord_part.to_s
|
392
|
+
if ord_part[0] == '-' # First char '-' means descending order
|
393
|
+
ord_part.slice!(0)
|
394
|
+
is_desc = true
|
395
|
+
end
|
396
|
+
if ord_part[0] == '~' # Char '~' means order NULLs as highest values instead of lowest
|
397
|
+
ord_part.slice!(0)
|
398
|
+
# (Unfortunately SQLServer does not support NULLS FIRST / NULLS LAST, so leave them out.)
|
399
|
+
is_nulls_switch = case ActiveRecord::Base.connection.adapter_name
|
400
|
+
when 'PostgreSQL', 'OracleEnhanced', 'SQLite'
|
401
|
+
:pg
|
402
|
+
when 'Mysql2', 'Trilogy'
|
403
|
+
:mysql
|
404
|
+
end
|
405
|
+
end
|
406
|
+
if _br_hm_counts.key?(ord_part_sym = ord_part.to_sym)
|
407
|
+
ord_part = +"\"b_r_#{ord_part}_ct\""
|
408
|
+
elsif _br_bt_descrip.key?(ord_part_sym)
|
409
|
+
ord_part = _br_bt_descrip.fetch(ord_part_sym, nil)&.first&.last&.first&.last&.dup
|
410
|
+
elsif !_br_cust_cols.key?(ord_part_sym) && !column_names.include?(ord_part)
|
394
411
|
# Disallow ordering by a bogus column
|
395
412
|
# %%% Note this bogus entry so that Javascript can remove any bogus _brick_order
|
396
413
|
# parameter from the querystring, pushing it into the browser history.
|
397
414
|
ord_part = nil
|
398
415
|
end
|
416
|
+
|
399
417
|
if ord_part
|
400
|
-
|
401
|
-
|
402
|
-
|
418
|
+
ord_part << ' DESC' if is_desc
|
419
|
+
ord_part << (is_desc ? ' NULLS LAST' : ' NULLS FIRST') if is_nulls_switch == :pg
|
420
|
+
ord_part.insert(0, '-') if is_nulls_switch == :mysql
|
421
|
+
|
422
|
+
order_by_txt&.<<("Arel.sql(#{ord_part.inspect})")
|
423
|
+
|
424
|
+
# # Retain any reference to a bt_descrip as being a symbol
|
425
|
+
# # Was: "#{quoted_table_name}.\"#{ord_part}\""
|
426
|
+
# order_by_txt&.<<(_br_bt_descrip.key?(ord_part) ? ord_part : ord_part.inspect)
|
403
427
|
s << ord_part
|
404
428
|
end
|
405
429
|
end
|
@@ -670,7 +694,6 @@ module ActiveRecord
|
|
670
694
|
# Add derived table JOIN for the has_many counts
|
671
695
|
nix = []
|
672
696
|
klass._br_hm_counts.each do |k, hm|
|
673
|
-
num_bt_things = 0
|
674
697
|
count_column = if hm.options[:through]
|
675
698
|
# Build the chain of JOINs going to the final destination HMT table
|
676
699
|
# (Usually just one JOIN, but could be many.)
|
@@ -691,7 +714,11 @@ module ActiveRecord
|
|
691
714
|
# Turn the last member of link_back into a foreign key
|
692
715
|
link_back << hmt_assoc.source_reflection.foreign_key
|
693
716
|
# If it's a HMT based on a HM -> HM, must JOIN the last table into the mix at the end
|
694
|
-
|
717
|
+
this_hm = hm
|
718
|
+
while !(src_ref = this_hm.source_reflection).belongs_to? && (thr = src_ref.options[:through])
|
719
|
+
through_sources.push(this_hm = src_ref.active_record.reflect_on_association(thr))
|
720
|
+
end
|
721
|
+
through_sources.push(src_ref) unless src_ref.belongs_to?
|
695
722
|
from_clause = +"#{through_sources.first.table_name} br_t0"
|
696
723
|
fk_col = through_sources.shift.foreign_key
|
697
724
|
|
@@ -700,9 +727,7 @@ module ActiveRecord
|
|
700
727
|
through_sources.map do |a|
|
701
728
|
from_clause << "\n LEFT OUTER JOIN #{a.table_name} br_t#{idx += 1} "
|
702
729
|
from_clause << if (src_ref = a.source_reflection).macro == :belongs_to
|
703
|
-
nm = hmt_assoc.source_reflection.inverse_of&.name
|
704
|
-
link_back << nm
|
705
|
-
num_bt_things += 1
|
730
|
+
link_back << (nm = hmt_assoc.source_reflection.inverse_of&.name)
|
706
731
|
# puts "BT #{a.table_name}"
|
707
732
|
"ON br_t#{idx}.#{a.active_record.primary_key} = br_t#{idx - 1}.#{a.foreign_key}"
|
708
733
|
elsif src_ref.options[:as]
|
@@ -723,9 +748,8 @@ module ActiveRecord
|
|
723
748
|
end
|
724
749
|
else # Standard has_many or has_one
|
725
750
|
# puts "HM #{a.table_name}"
|
726
|
-
# binding.pry unless (
|
727
751
|
nm = hmt_assoc.source_reflection.inverse_of&.name
|
728
|
-
#
|
752
|
+
# binding.pry unless nm
|
729
753
|
link_back << nm # if nm
|
730
754
|
"ON br_t#{idx}.#{a.foreign_key} = br_t#{idx - 1}.#{a.active_record.primary_key}"
|
731
755
|
end
|
@@ -742,16 +766,8 @@ module ActiveRecord
|
|
742
766
|
nix << k
|
743
767
|
next
|
744
768
|
elsif src_ref.macro == :belongs_to # Traditional HMT using an associative table
|
745
|
-
# binding.pry if link_back.length > 2
|
746
769
|
"br_t#{idx}.#{hm.foreign_key}"
|
747
770
|
else # A HMT that goes HM -> HM, something like Categories -> Products -> LineItems
|
748
|
-
# %%% Currently flaky, so will revisit this soon, probably while implementing the whole link_back architecture
|
749
|
-
if num_bt_things > 1
|
750
|
-
# binding.pry
|
751
|
-
nix << k
|
752
|
-
next
|
753
|
-
end
|
754
|
-
|
755
771
|
"br_t#{idx}.#{src_ref.active_record.primary_key}"
|
756
772
|
end
|
757
773
|
else
|
@@ -845,7 +861,8 @@ JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', '
|
|
845
861
|
# or custom columns as they must be expanded to find the corresponding b_r_model__column
|
846
862
|
# or br_cc_column naming for each.
|
847
863
|
if order_by.present?
|
848
|
-
|
864
|
+
order_by, _ = klass._brick_calculate_ordering(order_by, true) # Don't do the txt part
|
865
|
+
final_order_by = order_by.each_with_object([]) do |v, s|
|
849
866
|
if v.is_a?(Symbol)
|
850
867
|
# Add the ordered series of columns derived from the BT based on its DSL
|
851
868
|
if (bt_cols = klass._br_bt_descrip[v])
|
@@ -1140,7 +1157,7 @@ Module.class_exec do
|
|
1140
1157
|
base_module.const_set(schema_name.to_sym, (built_module = Module.new))
|
1141
1158
|
|
1142
1159
|
[built_module, "module #{schema_name}; end\n"]
|
1143
|
-
#
|
1160
|
+
# %%% Perhaps an option to use the first module just as schema, and additional modules as namespace with a table name prefix applied
|
1144
1161
|
|
1145
1162
|
# AVO Resource
|
1146
1163
|
elsif base_module == Object && Object.const_defined?('Avo') && requested.end_with?('Resource') &&
|
@@ -1786,8 +1803,7 @@ class Object
|
|
1786
1803
|
|
1787
1804
|
# %%% Allow params to define which columns to use for order_by
|
1788
1805
|
# Overriding the default by providing a querystring param?
|
1789
|
-
|
1790
|
-
order_by, _ = real_model._brick_calculate_ordering(ordering, true) # Don't do the txt part
|
1806
|
+
order_by = params['_brick_order']&.split(',')&.map(&:to_sym) || Object.send(:default_ordering, table_name, pk)
|
1791
1807
|
|
1792
1808
|
ar_relation = ActiveRecord.version < Gem::Version.new('4') ? real_model.preload : real_model.all
|
1793
1809
|
params['_brick_is_api'] = true if (is_api = request.format == :js || current_api_root)
|
@@ -1711,9 +1711,9 @@ end
|
|
1711
1711
|
<tr><td>(none)</td></tr>
|
1712
1712
|
<% else
|
1713
1713
|
collection2.each do |#{hm_singular_name}| %>
|
1714
|
-
<tr><td><%= br_descrip
|
1715
|
-
|
1716
|
-
|
1714
|
+
<tr><td><%= br_descrip = #{hm_singular_name}.brick_descrip(
|
1715
|
+
descrip_cols&.first&.map { |col| #{hm_singular_name}.send(col.last) }
|
1716
|
+
)
|
1717
1717
|
link_to(br_descrip, #{hm.first.klass._brick_index(:singular)}_path(slashify(#{obj_pk}))) %></td></tr>
|
1718
1718
|
<% end %>
|
1719
1719
|
<% end %>
|
data/lib/brick/version_number.rb
CHANGED
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.135
|
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
|
+
date: 2023-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|