- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/orm/entity.php
- Класс: BitrixMainORMEntity
- Вызов: Entity::appendField
protected function appendField(Field $field)
{
if (isset($this->fields[StringHelper::strtoupper($field->getName())]) && !$this->isClone)
{
trigger_error(sprintf(
'Entity `%s` already has Field with name `%s`.', $this->getFullName(), $field->getName()
), E_USER_WARNING);
return false;
}
if ($field instanceof Reference)
{
// references cache
$this->references[$field->getRefEntityName()][] = $field;
}
$this->fields[StringHelper::strtoupper($field->getName())] = $field;
if ($field instanceof ScalarField && $field->isPrimary())
{
$this->primary[] = $field->getName();
if($field->isAutocomplete())
{
$this->autoIncrement = $field->getName();
}
}
// add reference field for UField iblock_section
if ($field instanceof UField && $field->getTypeId() == 'iblock_section')
{
$refFieldName = $field->getName().'_BY';
if ($field->isMultiple())
{
$localFieldName = $field->getValueFieldName();
}
else
{
$localFieldName = $field->getName();
}
$newFieldInfo = array(
'data_type' => 'BitrixIblockSection',
'reference' => array($localFieldName, 'ID')
);
$newRefField = new Reference($refFieldName, $newFieldInfo['data_type'], $newFieldInfo['reference'][0], $newFieldInfo['reference'][1]);
$newRefField->setEntity($this);
$this->fields[StringHelper::strtoupper($refFieldName)] = $newRefField;
}
return true;
}