Find a model by its primary key or throw an exception.

@param  mixed  $id
@param  array  $columns
@return \Fly\Database\ActiveRecord\Model|Collection|static

@throws ModelNotFoundException
8907
public static function findOrFail($id, $columns = array('*'))
	{
		if ( ! is_null($model = static::find($id, $columns))) return $model;

		throw new ModelNotFoundException(get_called_class().' model not found');
	}
526241
protected function findModel($id)
    {
        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;
        $keys = $modelClass::primaryKey();
        if (count($keys) > 1) {
            $values = explode(',', $id);
            if (count($keys) === count($values)) {
                $model = $modelClass::findOne(array_combine($keys, $values));
            }
        } elseif ($id !== null) {
            $model = $modelClass::findOne($id);
        }

        if (isset($model)) {
            return $model;
        } else {
            throw new NotFoundHttpException("Object not found: '$id'");
        }
    }
162787
public function findByGuid($guid, $columns = [])
    {
        try {
            return $this->findByGuidOrFail($guid, $columns);
        } catch (ModelNotFoundException $e) {
            return false;
        }
    }
1318075
public function findByDn($dn, $columns = [])
    {
        try {
            return $this->findByDnOrFail($dn, $columns);
        } catch (ModelNotFoundException $e) {
            return false;
        }
    }
787982
def find_many(self, id, columns=None):
        
        if columns is None:
            columns = ["*"]

        if not id:
            return self._model.new_collection()

        self._query.where_in(self._model.get_qualified_key_name(), id)

        return self.get(columns)
715400
public function get($id, $rootId=NULL, array $columns=[])
    {
        $columns = $this->pickColumns($columns);
        $columnsId = $this->getColumnsCacheId($columns);

        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

        // If we have a root id, fill the cache by fetching the whole tree
        if ($rootId) {
            $this->tree($rootId, $columns);
        }

        // After retrieving the tree, look if it is now in cache
        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

        $result = $this->queryTreeById($id)
                       ->get($this->toSelectColumns($columns));

        $this->fillNodeCache($columnsId, $result);

        if (isset($this->_hierachyCache[$columnsId][$id])) {
            return $this->_hierachyCache[$columnsId][$id];
        }

    }
887353
public function findOrFailByUuid($uuid, $columns = ['*'])
    {
        $result = $this->findByUuid($uuid, $columns);

        if (is_array($uuid)) {
            if (count($result) == count(array_unique($uuid))) {
                return $result;
            }
        } elseif (! is_null($result)) {
            return $result;
        }

        throw new NotFoundHttpException('Resource \'' . class_basename(get_class($this->model)) . '\' with given UUID ' . $uuid . ' not found');
    }
414791
protected function select($columns=[])
    {
        $query = $this->model->newQuery()->getQuery();
        if ($columns) {
            $query->select($columns);
        }
        return $query;
    }
572603
public function findOrNew($id, $columns = ['*'])
	{
		if (is_null($instance = $this->find($id, $columns))) {
			$instance = $this->related->newInstance();

			$instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
		}

		return $instance;
	}
633842
public function findMany($ids, $columns = ['*'])
    {
        if (empty($ids)) {
            return $this->model->newCollection();
        }

        return $this->whereKey($ids)->get($columns);
    }
1353032
public function firstOrFail($columns = ['*'])
    {
        if (!is_null($entity = $this->first($columns))) {
            return $entity;
        }

        throw (new EntityNotFoundException())->setEntity(get_class($this->entityMap));
    }
906775
public function firstOrFail($columns = [])
    {
        $record = $this->first($columns);

        if (! $record) {
            throw (new ModelNotFoundException())
                ->setQuery($this->getUnescapedQuery(), $this->getDn());
        }

        return $record;
    }
340125
public function findOrFail($id, $columns = ['*'])
    {
        if (!is_null($entity = $this->find($id, $columns))) {
            return $entity;
        }

        throw (new EntityNotFoundException())->setEntity(get_class($this->entityMap));
    }
1114140
public static function findOrFail($ids, $columns = ['*'])
    {
        $result = self::find($ids, $columns);

        if (!is_null($result)) {
            return $result;
        }

        throw (new ModelNotFoundException)->setModel(
            __CLASS__, $ids
        );
    }
415707
public function getById($id, $col = null)
    {
        $id = (int) $id;
        $model = $this->getCacheItem($id);

        if (!$model) {
            $model = $this->getMapper()->getById($id, $col);

            if ($this->useCache) {
                $this->setCacheItem($id, $model);
            }
        }

        return $model;
    }
515159
public function find($id, $columns = ['*'])
    {
        if (is_array($id) || $id instanceof Arrayable) {
            return $this->findMany($id, $columns);
        }

        return $this->whereKey($id)->first($columns);
    }
1159696
public function find($value, $columns = [])
    {
        if (is_array($value)) {
            return $this->findMany($value, $columns);
        }

        // If we're not using ActiveDirectory, we can't use ANR. We'll make our own query.
        if (! is_a($this->schema, ActiveDirectory::class)) {
            return $this->prepareAnrEquivalentQuery($value)->first($columns);
        }

        return $this->findBy($this->schema->anr(), $value, $columns);
    }