• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/orm/objectify/entityobject.php
  • Класс: BitrixMainORMObjectifyEntityObject
  • Вызов: EntityObject::fill
public function fill($fields = FieldTypeMask::ALL)
{
	// object must have primary
	$primaryFilter = Query::filter();

	foreach ($this->sysRequirePrimary() as $primaryName => $primaryValue)
	{
		$primaryFilter->where($primaryName, $primaryValue);
	}

	// collect fields to be selected
	if (is_array($fields))
	{
		// go through IDLE fields
		$fieldsToSelect = $this->sysGetIdleFields($fields);
	}
	elseif (is_scalar($fields) && !is_numeric($fields))
	{
		// one custom field
		$fields = [$fields];
		$fieldsToSelect = $this->sysGetIdleFields($fields);
	}
	else
	{
		// get fields according to selector mask
		$fieldsToSelect = $this->sysGetIdleFieldsByMask($fields);
	}

	if (!empty($fieldsToSelect))
	{
		$fieldsToSelect = array_merge($this->entity->getPrimaryArray(), $fieldsToSelect);

		// build query
		$dataClass = $this->entity->getDataClass();
		$result = $dataClass::query()->setSelect($fieldsToSelect)->where($primaryFilter)->exec();

		// set object to identityMap of result, and it will be partially completed by fetch
		$im = new IdentityMap;
		$im->put($this);

		$result->setIdentityMap($im);
		$result->fetchObject();

		// set filled flag to collections
		foreach ($fieldsToSelect as $fieldName)
		{
			// check field before continue, it could be remote REF.ID definition so we skip it here
			if ($this->entity->hasField($fieldName))
			{
				$field = $this->entity->getField($fieldName);

				if ($field instanceof OneToMany || $field instanceof ManyToMany)
				{
					/** @var Collection $collection */
					$collection = $this->sysGetValue($fieldName);

					if (empty($collection))
					{
						$collection = $field->getRefEntity()->createCollection();
						$this->_actualValues[$fieldName] = $collection;
					}

					$collection->sysSetFilled();
				}
			}
		}
	}

	// return field value it it was only one
	if (is_array($fields) && count($fields) == 1 && $this->entity->hasField(current($fields)))
	{
		return $this->sysGetValue(current($fields));
	}

	return null;
}