lib/scaffolding_extensions/model/datamapper.rb
# Retrieve multiple objects given a hash of options
Retrieve multiple objects given a hash of options
Retrieve multiple objects given a hash of options
def scaffold_get_objects(options)
    optionshash = {}
    data = self.all
    if options[:conditions]
      conditions = options[:conditions]
      if conditions && Array === conditions && conditions.length > 0
        if String === conditions[0]
          data = data.all(:conditions => conditions)
        else
          conditions.each do |cond|
            next if cond.nil?
            data = case cond
              when Hash, String then data.all(:conditions => [cond.gsub("NULL","?"),nil])
              when Array then 
                if cond.length==1
                  data.all(:conditions => [cond[0].gsub("NULL","?"),nil])
                else
                  data.all(:conditions => cond)
                end
              when Proc then data.all(&cond)
            end
          end
        end
      end
    end
    slice = nil
    if options[:limit]
      startpos = options[:offset] || 0
      endpos = options[:limit]
      slice = [startpos,endpos]
    end
    if options[:order] then
      optionshash[:order] = get_ordering_options(options[:order])
    end
    if slice then
      q = data.all(optionshash).slice(*slice)
    else
      q = data.all(optionshash)
    end
    q.to_a
  end
def scaffold_get_objects ( options ) optionshash = { } data = self . all if options [ :conditions ] conditions = options [ :conditions ] if conditions && Array === conditions && conditions . length > 0 if String === conditions [ 0 ] data = data . all ( :conditions => conditions ) else conditions . each do | cond | next if cond . nil? data = case cond when Hash , String then data . all ( :conditions => [ cond . gsub ( "NULL" , "?" ) , nil ] ) when Array then if cond . length == 1 data . all ( :conditions => [ cond [ 0 ] . gsub ( "NULL" , "?" ) , nil ] ) else data . all ( :conditions => cond ) end when Proc then data . all ( & cond ) end end end end end slice = nil if options [ :limit ] startpos = options [ :offset ] || 0 endpos = options [ :limit ] slice = [ startpos , endpos ] end if options [ :order ] then optionshash [ :order ] = get_ordering_options ( options [ :order ] ) end if slice then q = data . all ( optionshash ) . slice ( * slice ) else q = data . all ( optionshash ) end q . to_a end
Retrieve multiple objects given a hash of options
Retrieve multiple objects given a hash of options
# TODO includes break SQL generation # optionshash[:links] = options[:include] if options[:include] # optionshash[:links] = [optionshash[:links]] unless optionshash[:links].is_a?(Array) #p repository.adapter.send("select_statement",q.query)
options
<not_specific>