lib/pluck_all.rb in pluck_all-1.0.1 vs lib/pluck_all.rb in pluck_all-1.1.0

- old
+ new

@@ -58,10 +58,29 @@ relation.select_values = args return klass.connection.select_all(relation.to_sql) #return klass.connection.select_all(relation.arel) end end + + +class ActiveRecord::Relation + if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('4.0.2') + def pluck_array(*args) + return pluck_all(*args).map{|hash| + result = hash.values #P.S. 這裡是相信ruby 1.9以後,hash.values的順序跟insert的順序一樣。 + next (result.one? ? result.first : result) + } + end + else + alias_method :pluck_array, :pluck if not method_defined?(:pluck_array) + end +end + + class ActiveRecord::Base def self.pluck_all(*args) self.where('').pluck_all(*args) + end + def self.pluck_array(*args) + self.where('').pluck_array(*args) end end