backframe 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/backframe/activerecord/filter_sort.rb +18 -8
- data/lib/backframe/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba1e52c321642997db0b9688fe95319d6cda0c8
|
4
|
+
data.tar.gz: 1aad76b7e76e089e362f6da0c523a4b0109713e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5996128d3b7f7660dffd109a555ec315ddfadbd84b934ecf770a0e551551430239fa70ccf47a75003e7ad8c4e3086cf09a1e954480aa62ad0b19648f21533a9
|
7
|
+
data.tar.gz: c1fbeb7c121da645bd4535aa1f2d8c1874bd7142c9c5288df2f85f1eec8c3a36d74e9b5f7348595e863faee1b265b54d53fb73fb565fd391b6d15775339ba5c3
|
@@ -49,16 +49,26 @@ module Backframe
|
|
49
49
|
|
50
50
|
def _sort(relation, key, order, default_key = 'created_at', default_order = 'desc', included = nil)
|
51
51
|
sortfields = {}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
sortjoins = {}
|
53
|
+
self.columns.each do |column|
|
54
|
+
sortfields[column.name] = "\"#{self.table_name}\".\"#{column.name}\""
|
55
|
+
end
|
56
|
+
model_table = self.table_name
|
57
|
+
associations = self.reflect_on_all_associations(:belongs_to)
|
58
|
+
associations.each do |association|
|
59
|
+
association_name = association.name
|
60
|
+
association_table = association.class_name.constantize.table_name
|
61
|
+
association_foreign_key = association.foreign_key
|
62
|
+
sortjoins["#{association.name}"] = "LEFT OUTER JOIN \"#{association_table}\" #{association_name} ON (\"#{association_name}\".\"id\" = \"#{model_table}\".\"#{association_foreign_key}\")"
|
63
|
+
association.class_name.constantize.columns.each do |column|
|
64
|
+
sortfields["#{association_name}.#{column.name}"] = "\"#{association_name}\".\"#{column.name}\""
|
57
65
|
end
|
58
66
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
key = (key.present? && sortfields.has_key?(key)) ? key : 'created_at'
|
68
|
+
order = (order.present?) ? order : 'desc'
|
69
|
+
if parts = key.match(/(\w*)\.(\w*)/)
|
70
|
+
relation = relation.joins(sortjoins[parts[1]])
|
71
|
+
end
|
62
72
|
relation.order("#{sortfields[key]} #{order}")
|
63
73
|
end
|
64
74
|
end
|
data/lib/backframe/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backframe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Kops
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-05-
|
12
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: write_xlsx
|