Returns a scope that limits results any occurrences of the specified record.
 Record can be specified by passing a staging record, or an id and table_name.
186376
def matching(staging_record, table_name = nil)
      table_name, id = Stagehand::Key.generate(staging_record, :table_name => table_name)
      prepare_to_modify(table_name)
      return Record.where(:id => id)
    end
670580
def name_include(records, filter_regex):
    
    logging.info('Applying _name_include generator: '
                 'including only IDs matching ' + filter_regex +
                 ' in results.')
    regex = re.compile(filter_regex)
    for record in records:
        if regex.search(record.id) or regex.search(record.description):
            yield record
1363444
def find_by!(conditions = {})
      result = find_by(conditions)
      if result.nil?
        raise RecordNotFound.new("Couldn't find #{name} with '#{conditions.keys.first}'=#{conditions.values.first}")
      end
      result
    end
448232
private BaseTable getPhysicalTable(PassThruTable table, Record record)
    {
    	BaseTable altTable = table.getNextTable();
		if (altTable instanceof PassThruTable)
		{
			BaseTable physicalTable = getPhysicalTable((PassThruTable)altTable, record);
			if (physicalTable != null)
				if (physicalTable != altTable)
					return physicalTable;
		}
		else
			if (altTable.getDatabase().getDatabaseName(true).equals(record.getTable().getDatabase().getDatabaseName(true)))
				return altTable;
    	
    	Iterator<BaseTable> tables = table.getTables();
    	while (tables.hasNext())
    	{
    		altTable = tables.next();
    		if (altTable instanceof PassThruTable)
    		{
    			BaseTable physicalTable = getPhysicalTable((PassThruTable)altTable, record);
    			if (physicalTable != null)
    				if (physicalTable != altTable)
    					return physicalTable;
    		}
    		else 
    			if (altTable.getDatabase().getDatabaseName(true).equals(record.getTable().getDatabase().getDatabaseName(true)))
    				return altTable;
    	}
    	return table;
    }
491611
def __restrictIndex(self, i):
        """"""
        if self.numRecords:
            rmax = self.numRecords - 1
            if abs(i) > rmax:
                raise IndexError("Shape or Record index out of range.")
            if i < 0: i = range(self.numRecords)[i]
        return i
131289
public List evaluate(Record record) {
    // fast path (not functionally necessary):
    if (fields.size() == 1) {
      Object first = fields.get(0);
      if (first instanceof String) {
        return Collections.singletonList(first);
      } else {
        String ref = ((Field) first).getName();
        if (ref.length() != 0) {
          List resolvedValues = record.get(ref);
          return resolvedValues;
        }
      }
    }

    // slow path:
    ArrayList<Object> results = new ArrayList<Object>(1);
    evaluate2(0, record, new StringBuilder(), results);
    return results;
  }
703621
def get_find_all_query(self, table_name, constraints=None, *, columns=None, order_by=None,
                         limiting=(None, None)):
    
    where, params = self.parse_constraints(constraints)

    if columns:
      if isinstance(columns, str):
        pass
      else:
        columns = ", ".join(columns)
    else:
      columns = "*"

    if order_by:
      order = " order by {0}".format(order_by)
    else:
      order = ""

    paging = ""
    if limiting is not None:
      limit, offset = limiting
      if limit is not None:
        paging += " limit {0}".format(limit)
      if offset is not None:
        paging += " offset {0}".format(offset)

    return ("select {0} from {1} where {2}{3}{4}".format(
      columns,
      table_name,
      where or "1 = 1",
      order,
      paging
    ), params)
1272465
def iterateFilteredRecords( dbid, fieldNames, query = nil, qid = nil, qname = nil, clist = nil, slist = nil, fmt = "structured", options = nil )
      fields = []
      regexp = {}
      fieldNames.each{|field|
         if field.is_a?(Hash)
            fields << field.keys[0]
            regexp[field.keys[0]] = field.values[0]
         elsif field.is_a?(String)
            fields << field
         end
      }
      regexp = nil if regexp.length == 0
      iterateRecords(dbid,fields,query,qid,qname,clist,slist,fmt,options){|record|
         if regexp
            match = true
            fields.each{|field|
               if regexp[field] 
                  unless record[field] and record[field].match(regexp[field])
                     match = false 
                     break
                  end
               end
            }
            yield record if match
         else
            yield record
         end
      }
   end
880750
def get_unique_record(self, sql, parameters = None, quiet = False, locked = False):
        ''''''
        results = self.execute_select(sql, parameters = parameters, quiet = quiet, locked = locked)
        assert(len(results) == 1)
        return results[0]
228739
def empty?
      return @records.empty? if loaded?

      if limit_value == 0
        true
      else
        # FIXME: This count is not compatible with #select('authors.*') or other select narrows
        c = count
        c.respond_to?(:zero?) ? c.zero? : c.empty?
      end
    end
1045927
def find_by(self, values={}, **kwargs):
        
        try:
            return self(
                **self.select(
                    where=values,
                    limit=1,
                    **kwargs
                    ).to_dict(orient='records')[0]
                )
        except IndexError:
            return None
1067632
async def filter_by(cls, db, offset=None, limit=None, **kwargs):
        
        if limit and type(limit) is not int:
            raise InvalidQuery('If limit is supplied it must be an int')
        if offset and type(offset) is not int:
            raise InvalidQuery('If offset is supplied it must be an int')

        ids_to_iterate = await cls._get_ids_filter_by(db, **kwargs)
        if offset:
            # Using offset without order_by is pretty strange, but allowed
            if limit:
                ids_to_iterate = ids_to_iterate[offset:offset+limit]
            else:
                ids_to_iterate = ids_to_iterate[offset:]
        elif limit:
            ids_to_iterate = ids_to_iterate[:limit]

        for key in ids_to_iterate:
            yield await cls.load(db, key)
957901
def getAllRecordIDs( dbid )
      rids = []
      if dbid
         getSchema( dbid )
         next_record_id = getResponseElement( "table/original/next_record_id" )
         if next_record_id and next_record_id.has_text?
            next_record_id = next_record_id.text
            (1..next_record_id.to_i).each{ |rid|
               begin
                  _getRecordInfo( rid )
                  rids << rid.to_s if update_id
               rescue
               end
            }
         end
      end
      if block_given?
        rids.each { |id| yield id }
      else
        rids
      end
   end
818855
def set_records
      authorize! :read, resource.name.underscore.to_sym
      @records = request_collection.ransack(parsed_query).result
      @object = request_collection.new
      key_scope_records
      reorder_records if params[:sort].present?
      select_fields if params[:select].present?
      include_relations if params[:include].present?
    end
1288534
function recordResult (results) {
    // if only ids were selected the return result object to fetch records
    if (this.query.select.isSelectOnlyIds) {
        // build result object
        var result = new ImmutableCoreModelResult({
            query: this.query,
            results: results,
            applyView: true,
        })
        // return result or all records if specified
        return this.query.args.all ? result.all() : result
    }
    // otherwise return ImmutableCoreModelInstance record(s)
    else {
        // if query is for a single record then return record or undefined
        if (this.query.args.limit === 1) {
            // if there are not results return undefined
            if (!results.length) {
                return undefined
            }
            // apply model view to record
            return Promise.resolve(this.applyModelViewRecord(results[0]))
            // resolve with instance
            .then(result => this.newRecordInstance(result))
        }
        // if query is for all records then return all
        else {
            // apply model views to each record
            return Promise.map(results, result => {
                // apply model view to record
                return this.applyModelViewRecord(result)
                // resolve with instance
                .then(result => this.newRecordInstance(result))
            })
        }
    }
}
671766
def records_for(query)
#      STDERR.puts "records_for(#{query})"
#      STDERR.puts "records_for(#{query.inspect})"
      records = []
      if query.conditions.nil?
	raise "query.conditions.nil?" # FIXME
      else
	query.conditions.operands.each do |operand|
	  if operand.is_a?(DataMapper::Query::Conditions::OrOperation)
	    operand.each do |op|
	      records = records + perform_query(query, op)
	    end
	  else
	    records = perform_query(query, operand)
	  end
	end
      end      
      records
    end
753452
def limit(self, limit):
        
        query = self._copy()
        query._limit = limit
        return query