Selaa lähdekoodia

Added ability to use hashes for smart columns - #86, closes #78

Andrew Kane 8 vuotta sitten
vanhempi
commit
62e42b5547
2 muutettua tiedostoa jossa 8 lisäystä ja 3 poistoa
  1. 1 0
      CHANGELOG.md
  2. 7 3
      lib/blazer/result.rb

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@
 
 - Cancel all queries on page nav
 - Prevent Ace from taking over find command
+- Added ability to use hashes for smart columns
 
 ## 1.7.1
 

+ 7 - 3
lib/blazer/result.rb

@@ -25,9 +25,13 @@ module Blazer
         columns.each_with_index do |key, i|
           query = data_source.smart_columns[key]
           if query
-            values = rows.map { |r| r[i] }.compact.uniq
-            result = data_source.run_statement(ActiveRecord::Base.send(:sanitize_sql_array, [query.sub("{value}", "(?)"), values]))
-            boom[key] = Hash[result.rows.map { |k, v| [k.to_s, v] }]
+            if query.is_a?(Hash)
+              boom[key] = query.stringify_keys
+            else
+              values = rows.map { |r| r[i] }.compact.uniq
+              result = data_source.run_statement(ActiveRecord::Base.send(:sanitize_sql_array, [query.sub("{value}", "(?)"), values]))
+              boom[key] = Hash[result.rows.map { |k, v| [k.to_s, v] }]
+            end
           end
         end
         boom