Attempts to find an instance of klass (which must be an ActiveRecord object) with id primary key
 Returns record from current if it's included or find from DB
331277
def record_from_current_or_find(klass, id, current)
      if current.is_a?(ActiveRecord::Base) && current.id.to_s == id
        # modifying the current object of a singular association
        current
      elsif current.respond_to?(:any?) && current.any? { |o| o.id.to_s == id }
        # modifying one of the current objects in a plural association
        current.detect { |o| o.id.to_s == id }
      else # attaching an existing but not-current object
        klass.find(id)
      end
    end
917301
public function get($class=null)
	{
		$class = $this->get_class($class);

		if (isset($this->reflections[$class]))
			return $this->reflections[$class];

		throw new ActiveRecordException("Class not found: $class");
	}
938929
def exists(self, model_class, ID):
        ''''''

        assert hasattr(model_class, '_fields'), 'Not a valid model class'
        res = self.get(model_class, id=ID, fetchOne=True)
        if res:
            return True
        return False
1058947
def get_one(cls, db, *args, **kwargs):
        
        data = db[cls.collection].find_one(*args, **kwargs)
        if data:
            return cls.wrap_incoming(data, db)
        else:
            return None
568808
def inspect
      objects = collection
        .map { |id, _| cached(id) || klass.new(klass.schema.primary_key => id) }
        .map { |object| object.to_s }

      "#<#{self.class.name} [#{objects.join(', ')}]>"
    end
886389
def find_by(conditions = {})
      to_a.detect do |record|
        Find.new(record).is_of(conditions)
      end
    end
1306633
def get_or_exception(cls, id):
        '''  '''
        obj = cls.get(id)

        if obj is None:
            raise ModelNotFoundError('This object does not exist in database')

        return obj
55974
def update(self, instance):
        
        assert isinstance(instance, self.model_klass)
        if instance.db_id:
            query = {'_id': ObjectId(instance.db_id)}
        else:
            query = build_db_query(self.primary_key, instance.key)
        self.ds.update(self.collection_name, query, instance)
        return instance.db_id
1289847
def find_with_static_record(*args)#:nodoc:
      if scope(:find).nil? && args
        if args.first.is_a?(Fixnum) &&
            ((args.length == 1 ||
            (args[1].is_a?(Hash) && args[1].values.delete(nil).nil?)))
          return static_record_cache[:primary_key][args.first]
        elsif args.first == :all && args.length == 1
          return static_record_cache[:primary_key].values
        end
      end

      find_without_static_record(*args)
    end
965500
def using_single_table_inheritance?(klass, record)
      inheritance_column = klass.inheritance_column
      record[inheritance_column].present? && record.has_attribute?(inheritance_column)
    end
1090017
def object( object_name )
      object = objects.find do |obj|
        obj[ 'name' ] == object_name
      end

      if !object
        raise "Database #{name} does not have an object named '#{object_name}'."
      end

      klass = PSQL.const_get object[ 'type' ].capitalize
      klass.new object[ 'name' ], name
    end
844584
def find(handle)
      handle = build_handle(handle)
      entity_hash = get_data(handle)
      entity = build(entity_hash)
      entity.persisted = true
      entity
    end
388674
private ClassRecord getClassRecord(EntityIdValue entityIdValue) {
		if (!this.classRecords.containsKey(entityIdValue)) {
			ClassRecord classRecord = new ClassRecord();
			this.classRecords.put(entityIdValue, classRecord);
			return classRecord;
		} else {
			return this.classRecords.get(entityIdValue);
		}
	}
1153893
def find_one(self, cls, id):
        """"""
        try:
            db_result = self.get_class_table(cls).lookup(id)
        except ItemNotFound:
            # according to docs, this shouldn't be required, but it IS
            db_result = None

        if not db_result:
            return None

        obj = cls.from_data(db_result['value'])
        return obj
1274213
def get_one(self, key):
        
        query = build_db_query(self.primary_key, key)
        collection = self.ds.connection(self.collection_name)

        document = collection.find_one(query)
        if document is None:
            raise LookupError('{0} with key {1} was not found'.format(self.model_klass.__name__, query))
        return self.model_klass.from_json(document)
620369
private static Field recordIdFieldIn(Class klass) {
        for (Field field : klass.getDeclaredFields()) {
            if (field.isAnnotationPresent(RecordId.class)) {
                return field;
            }
        }
        Class superclass = klass.getSuperclass();
        if (superclass != null) {
            return recordIdFieldIn(superclass);
        }
        throw new RecordIdNotFoundException(klass);
    }
296245
def characterize(cls, record):
        
        classes = list(cls.__subclasses__())
        if not isabstract(cls):
            classes.append(cls)
        for subclass in classes:
            entity = subclass(record)
            if entity.is_valid():
                return entity
        raise RuntimeError("could not find the type for '{}'".format(record.id))