effective_datatables 2.2.10 → 2.2.11

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: c8df18bd0c74dc210b4825617d73e5e7a4000948
4
- data.tar.gz: 9465d7616e52566bfbbb395c365baf8b854f9c90
3
+ metadata.gz: 925dbdcde129594000b35c33bdcca9d40a2270a2
4
+ data.tar.gz: 45aaec09d5196309e7975c51de52ad97f2d52690
5
5
  SHA512:
6
- metadata.gz: 50946449d7c9c9fc3c7cbcea28d62486d82c58191390715cff5363592a511362e052867d4d47362c36fbacf03ce27a40ea9f9c84ef35db7806c563bb7d14704f
7
- data.tar.gz: dee241d33a01cc8d025f20afc868ad1806635cb51cae3fdbd4ae028d4a19062b6a1b534d01682c239f2bd132910f03b32dab5e0261050e8ebee2062f2e28e4c8
6
+ metadata.gz: 3cd98bc405d0be8aa0da7c8fccbc0657334bdb619ffef1f4f114051ec1ab2ab8d5ace4806da40ce2178855118e351fba9b03d357599e4a04cd080f82b24ee049
7
+ data.tar.gz: d743c635c18acb6b64a051e944fcc787e57f753f6b3a0767da299711262542dcca7e5d146f02885e9e1bc91d28c0c2950d5bb0e34c7bde8639d36dd29ceeec07
@@ -72,19 +72,33 @@ module Effective
72
72
  collection
73
73
  end
74
74
  when :has_many
75
- inverse_ids = term.split(',').map { |term| (term = term.to_i) == 0 ? nil : term }.compact
76
- return collection unless inverse_ids.present?
77
-
78
75
  reflection = collection.klass.reflect_on_association(table_column[:name].to_sym)
79
76
  raise "unable to find #{collection.klass.name} :has_many :#{table_column[:name]} association" unless reflection
80
77
 
81
- obj = reflection.build_association({}) # Clinic
78
+ obj = reflection.build_association({})
82
79
  klass = obj.class
83
80
 
84
81
  inverse = reflection.inverse_of || klass.reflect_on_association(collection.table_name) || obj.class.reflect_on_association(collection.table_name.singularize)
85
82
  raise "unable to find #{klass.name} has_many :#{collection.table_name} or belongs_to :#{collection.table_name.singularize} associations" unless inverse
86
83
 
87
- ids = klass.where(id: inverse_ids).joins(inverse.name).pluck(inverse.foreign_key)
84
+ ids = if [:select, :grouped_select].include?(table_column[:filter][:type])
85
+ # Treat the search term as one or more IDs
86
+ inverse_ids = term.split(',').map { |term| (term = term.to_i) == 0 ? nil : term }.compact
87
+ return collection unless inverse_ids.present?
88
+
89
+ klass.where(id: inverse_ids).joins(inverse.name).pluck(inverse.foreign_key)
90
+ else
91
+ # Treat the search term as a string.
92
+ klass_columns = if (table_column[:column] == klass.table_name) # No custom column has been defined
93
+ klass.columns.map { |col| col.name if col.text? }.compact # Search all database text? columns
94
+ else
95
+ [table_column[:column].gsub("#{klass.table_name}.", '')] # table_column :order_items, column: 'order_items.title'
96
+ end
97
+
98
+ conditions = klass_columns.map { |col_name| "#{klass.table_name}.#{col_name} #{ilike} :term" }
99
+
100
+ klass.where(conditions.join(' OR '), term: "%#{term}%", num: term.to_i).joins(inverse.name).pluck(inverse.foreign_key)
101
+ end
88
102
 
89
103
  collection.public_send(sql_op, id: ids)
90
104
  when :obfuscated_id
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '2.2.10'.freeze
2
+ VERSION = '2.2.11'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.10
4
+ version: 2.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails