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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c0d24ab06f49de1e0896bfbb425d52178e8acfd
4
- data.tar.gz: f52fdfa058db885a75eb55e98f374190a0b6407a
3
+ metadata.gz: 0ba1e52c321642997db0b9688fe95319d6cda0c8
4
+ data.tar.gz: 1aad76b7e76e089e362f6da0c523a4b0109713e0
5
5
  SHA512:
6
- metadata.gz: 540f5dd53eaed8e5d1281ba0bc7000061e2e7d31ba10d971c310198f57b9b905b66059d7a795d44d231461ab016b445688e27706c0cb9514a8d329e98cb936fa
7
- data.tar.gz: 45fa7b20bb8deba3a1f8e9f8f5c86faf272fbd65cbcfaac94aab730c0b7e652634abcdad9eb14f804adb8cd917fa1ca7ea1674eb7a43284b5db388cf392d01a2
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
- included ||= [self]
53
- included.each do |model|
54
- model.columns.each do |column|
55
- sortkey = (model == self) ? column.name : "#{model.table_name.singularize}.#{column.name}"
56
- sortfields[sortkey] = "\"#{model.table_name}\".\"#{column.name}\""
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
- key = (key.present? && sortfields.has_key?(key)) ? key : default_key
61
- order = (order.present?) ? order : default_order
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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Backframe
4
- VERSION = '0.0.21'
4
+ VERSION = '0.0.22'
5
5
  end
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.21
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 00:00:00.000000000 Z
12
+ date: 2016-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: write_xlsx