Class ActiveRecord::Extensions::ArrayExt
In: lib/ar-extensions/extensions.rb
Parent: Object

ActiveRecord::Extension to translate an Array of values into the approriate IN( … ) or NOT IN( … ) SQL.

Examples

 Model.find :all, :conditions=>{ :id => [ 1,2,3 ] }

 # the following three calls are equivalent
 Model.find :all, :conditions=>{ :id_ne => [ 4,5,6 ] }
 Model.find :all, :conditions=>{ :id_not => [ 4,5,6 ] }
 Model.find :all, :conditions=>{ :id_not_in => [ 4,5,6 ] }

Methods

process  

Constants

NOT_EQUAL_RGX = /(.+)_(ne|not|not_in)/

Public Class methods

[Source]

     # File lib/ar-extensions/extensions.rb, line 179
179:     def self.process( key, val, caller )
180:       if val.is_a?( Array )
181:         match_data = key.to_s.match( NOT_EQUAL_RGX )
182:         key = match_data.captures[0] if match_data
183:         str = "#{caller.table_name}.#{caller.connection.quote_column_name( key )} " +
184:           (match_data ? 'NOT ' : '') + "IN( ? )"
185:         return Result.new( str, val )
186:       end
187:       nil
188:     end

[Validate]