lib/scaffolding_extensions/meta_model.rb
# Searches for objects that meet the criteria specified by options:
# - :null: fields that must be must be NULL
# - :notnull: matching fields must be NOT NULL
# - :model: hash with field name strings as keys and strings as values.
#   uses the value for each field to search.  Strings are searched based on
#   substring, other values have to be an exact match.
# - :page: To determine which offset to use
#
# Returns [form_params, objects], where form_params are a list of parameters
# for the results form (for going to the next/previous page), and objects are
# all of the objects that matched.


Returns [form_params, objects], where form_params are a list of parameters
for the results form (for going to the next/previous page), and objects are
all of the objects that matched.
Returns [ form_params objects ] where form_params are a list of parameters for the results form ( for going to the next / previous page ) and objects are all of the objects that matched .
def scaffold_search(options)
    conditions = []
    search_model = options[:model] || {}
    object = scaffold_search_object(search_model)
    null = options[:null]
    notnull = options[:notnull]
    form_params= {:model=>{}, :null=>[], :notnull=>[], :page=>options[:page]}
    limit, offset = nil, nil
    if scaffold_search_pagination_enabled?
      limit = scaffold_search_results_limit + 1
      offset = options[:page] > 1 ? (limit-1)*(options[:page] - 1) : nil
    end
    if search_model
      scaffold_attributes(:search).each do |field|
        fsym = field
        field = field.to_s
        next if (null && null.include?(field)) || \
            (notnull && notnull.include?(field)) || \
            search_model[field].nil? || search_model[field].empty?
        case scaffold_column_type(fsym)
          when :string, :text
            conditions << scaffold_substring_condition(field, object.send(field))
          else
            conditions << scaffold_equal_condition(field, object.send(field))
          end
        form_params[:model][field] = search_model[field] if scaffold_search_pagination_enabled?
      end
    end
    scaffold_attributes(:search).each do |field|
      field = field.to_s
      if null && null.include?(field)
        conditions << scaffold_null_condition(field)
        form_params[:null] << field if scaffold_search_pagination_enabled?
      end
      if notnull && notnull.include?(field)
        conditions << scaffold_notnull_condition(field)
        form_params[:notnull] << field if scaffold_search_pagination_enabled?
      end
    end
    conditions << scaffold_session_conditions(options[:session])
    objects = scaffold_get_objects(:conditions=>conditions, :include=>scaffold_include(:search), :order=>scaffold_select_order(:search), :limit=>limit, :offset=>offset)
    if scaffold_search_pagination_enabled? && objects.length == scaffold_search_results_limit+1
      form_params[:next_page] = true
      objects.pop
    end
    [form_params, objects]
  end
def scaffold_search ( options ) conditions = [ ] search_model = options [ :model ] || { } object = scaffold_search_object ( search_model ) null = options [ :null ] notnull = options [ :notnull ] form_params = { :model => { } , :null => [ ] , :notnull => [ ] , :page => options [ :page ] } limit , offset = nil , nil if scaffold_search_pagination_enabled? limit = scaffold_search_results_limit + 1 offset = options [ :page ] > 1 ? ( limit - 1 ) * ( options [ :page ] - 1 ) : nil end if search_model scaffold_attributes ( :search ) . each do | field | fsym = field field = field . to_s next if ( null && null . include? ( field ) ) || ( notnull && notnull . include? ( field ) ) || search_model [ field ] . nil? || search_model [ field ] . empty? case scaffold_column_type ( fsym ) when :string , :text conditions << scaffold_substring_condition ( field , object . send ( field ) ) else conditions << scaffold_equal_condition ( field , object . send ( field ) ) end form_params [ :model ] [ field ] = search_model [ field ] if scaffold_search_pagination_enabled? end end scaffold_attributes ( :search ) . each do | field | field = field . to_s if null && null . include? ( field ) conditions << scaffold_null_condition ( field ) form_params [ :null ] << field if scaffold_search_pagination_enabled? end if notnull && notnull . include? ( field ) conditions << scaffold_notnull_condition ( field ) form_params [ :notnull ] << field if scaffold_search_pagination_enabled? end end conditions << scaffold_session_conditions ( options [ :session ] ) objects = scaffold_get_objects ( :conditions => conditions , :include => scaffold_include ( :search ) , :order => scaffold_select_order ( :search ) , :limit => limit , :offset => offset ) if scaffold_search_pagination_enabled? && objects . length == scaffold_search_results_limit + 1 form_params [ :next_page ] = true objects . pop end [ form_params , objects ] end
Searches for objects that meet the criteria specified by options:
 :null: fields that must be must be NULL
 :notnull: matching fields must be NOT NULL
 :model: hash with field name strings as keys and strings as values.
Searches for objects that meet the criteria specified by options : : null : fields that must be must be NULL : notnull : matching fields must be NOT NULL : model : hash with field name strings as keys and strings as values .
options
<not_specific>