Finds a record by the specified attribute and value.

@param string       $attribute
@param string       $value
@param array|string $columns

@return Model|array|false
505727
public function findBy($attribute, $value, $columns = [])
    {
        try {
            return $this->findByOrFail($attribute, $value, $columns);
        } catch (ModelNotFoundException $e) {
            return false;
        }
    }
1014453
public function findByField($fieldName, $value) {
    $dataConnection = $this->app->getDataConnection($this->connection);
    if ($fieldName == $this->idColumn) {
      $value = $dataConnection->convertToNativeId($value);
    }
    $result = $dataConnection->findOneByField($fieldName, $value, $this->table, $this->readFields);
    if ($result == NULL) {
      return FALSE;
    }
    $this->load($result);
    return TRUE;
  }
227676
public function find($category, $attribute, $value) {
        $cmdbObjects = new CMDBObjects($this->api);

        $limit = 100;
        $offset = 0;

        $objectIDs = [];

        while (true) {
            $objects = $cmdbObjects->read([], $limit, $offset);

            $count = count($objects);

            if ($count === 0) {
                break;
            }

            foreach ($objects as $object) {
                $objectIDs[] = (int)$object['id'];
            }

            unset($objects);

            $cmdbCategory = new CMDBCategory($this->api);

            $result = $cmdbCategory->batchRead(
                $objectIDs,
                [$category]
            );

            $objectIDs = [];

            foreach ($result as $categoryEntries) {
                foreach ($categoryEntries as $categoryEntry) {
                    if (!array_key_exists($attribute, $categoryEntry)) {
                        continue;
                    }

                    $found = false;

                    if (is_array($categoryEntry[$attribute]) &&
                        array_key_exists('ref_title', $categoryEntry[$attribute]) &&
                        $categoryEntry[$attribute]['ref_title'] === $value
                    ) {
                        $found = true;
                    } elseif (is_array($categoryEntry[$attribute]) &&
                        array_key_exists('title', $categoryEntry[$attribute]) &&
                        $categoryEntry[$attribute]['title'] === $value
                    ) {
                        $found = true;
                    } elseif (is_numeric($categoryEntry[$attribute]) &&
                        is_int($value) &&
                        (int)$categoryEntry[$attribute] === $value
                    ) {
                        $found = true;
                    } elseif (is_string($categoryEntry[$attribute]) &&
                        is_string($value) &&
                        $categoryEntry[$attribute] === $value
                    ) {
                        $found = true;
                    }

                    if ($found === false) {
                        continue;
                    }

                    if (!array_key_exists('objID', $categoryEntry)) {
                        throw new RuntimeException('Found attribute for unknown object');
                    }

                    $objectIDs[] = (int)$categoryEntry['objID'];
                }
            }

            if ($count < $limit) {
                break;
            }

            $offset += $limit;
        }

        return $objectIDs;
    }
591910
public function findByField($field, $value = null, $columns = ['*'])
    {
        $this->applyCriteria();
        $this->applyScope();
        $model = $this->model->where($field, '=', $value)->get($columns);
        $this->resetModel();

        return $this->parserResult($model);
    }
1301590
public function setAttribute($attribute, $value): bool
    {
        $this->connect();

        return $this->pdo->setAttribute($attribute, $value);
    }
687738
public function findManyBy($attribute, array $values = [], $columns = [])
    {
        $query = $this->select($columns);

        foreach ($values as $value) {
            $query->orWhere([$attribute => $value]);
        }

        return $query->get();
    }
474955
public function find($find, $column = 'id', array $relations = [], array $columns = ['*'])
    {
        $this->model = $this->where($column, $find);
        $this->model = $this->relation->apply($this->model, $this, $relations);

        return $this->model->firstOrFail($columns);
    }
646712
public function set(string $column, $value)
    {
        if (method_exists($this, $this->getAttributeSetMethod($column))) {
            foreach ($this as $row) {
                $row[$column] = $value;
            }

            return $this;
        }

        $this->validateFillableColumn($column);

        foreach (array_keys($this->rows) as $key) {
            $this->setInRow($key, $column, $value);
        }
        unset($row);

        return $this;
    }
962409
public function findBy($columns, $value = null)
    {
        $this->loadAll();

        if (!is_array($columns)) {
            $columns = array($columns => $value);
        }

        $result = array();
        foreach ($this->allUnits as $u) {
            $status = true;
            foreach ($columns as $column => $value) {
                $unitValue = call_user_func(array($u, 'get'.ucfirst($column)));
                $status &= is_array($value) ? in_array($unitValue, $value) : $unitValue == $value;
            }
            if ($status) {
                $result[] = $u;
            }
        }

        return $result;
    }
951756
public function getBy($attribute, $value, $columns = array('*'))
    {
        return $this->model->where($attribute, '=', $value)->get($columns);
    }
111395
private function queryJunctionTable($table, $column, $value, $columns)
    {
        $rows = $this->queryTable($table, $column, array($value), $columns);

        foreach ($rows as &$row) {
            $row = $this->leaveOnlyCurrent($row, $column);
        }

        return $this->extractValues($rows);
    }
11339
public function findByOrFail($attribute, $value, $columns = [])
    {
        return $this->whereEquals($attribute, $value)->firstOrFail($columns);
    }
540692
protected function _set_eav($attribute, $value)
	{
		// get the current class name
		$class = get_called_class();

		// don't do anything unless we actually have an EAV container
		if (property_exists($class, '_eav'))
		{
			// loop through the defined EAV containers
			foreach (static::$_eav as $rel => $settings)
			{
				// normalize the container definition, could be string or array
				if (is_string($settings))
				{
					$rel = $settings;
					$settings = array();
				}

				// fetch the relation object for this EAV container
				if ( ! $relation = static::relations($rel))
				{
					throw new \OutOfBoundsException('EAV container defines a relation that does not exist in '.get_class($this).'.');
				}

				// EAV containers must be of the "Many type"
				if ($relation instanceOf \Orm\HasOne or $relation instanceOf \Orm\BelongsTo)
				{
					throw new \OutOfBoundsException('EAV containers can only be defined on "HasMany" or "ManyMany" relations in '.get_class($this).'.');
				}

				// determine attribute and value column names
				$attr = isset($settings['attribute']) ? $settings['attribute'] : 'attribute';
				$val = isset($settings['value']) ? $settings['value'] : 'value';

				// loop over the resultset
				foreach ($this->{$relation->name} as $key => $record)
				{
					if ($record->{$attr} === $attribute)
					{
						$record->{$val} = $value;
						return true;
					}
				}

				// not found, we've got outselfs a new attribute, so add it
				if ($rel = static::related_class($rel))
				{
					$this->{$relation->name}[] = $rel::forge(array(
						$attr => $attribute,
						$val => $value,
					));
					return true;
				}
			}
		}

		return false;
	}
213370
public function find($id, $columns = array('*'))
	{
		if (is_array($id))
		{
		    return $this->findMany($id, $columns);
		}

		$this->query->where($this->model->getKeyName(), '=', $id);

		return $this->first($columns);
	}
1046673
public T findOneByAttribute(String attribute, Object value) {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<T> query = cb.createQuery(getEntityClass());
        Root<T> from = query.from(getEntityClass());

        query.where(cb.equal(from.get(attribute), value));

        try {
            return getEntityManager().createQuery(query).getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }
999000
public function attribute($attribute, $value = null)
    {
        $element = clone $this;

        $element->attributes->setAttribute($attribute, (string) $value);

        return $element;
    }
470241
public function findAllBy($attribute, $value, $columns = ['*'])
    {
        return $this->model->where($attribute, '=', $value)->get($columns);
    }