• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/orm/commonelement.php
  • Класс: BitrixIblockORMCommonElement
  • Вызов: CommonElement::sysAddToCollection
public function sysAddToCollection($fieldName, $remoteObject)
{
	$fieldName = StringHelper::strtoupper($fieldName);
	$field = $this->entity->getField($fieldName);

	if ($field instanceof PropertyOneToMany)
	{
		// convert PropertyValue to regular relation object
		$remoteObject = $this->sysConvertPropertyValue($remoteObject, $field);

		// check for duplicates
		if (in_array(
			$field->getIblockElementProperty()->getPropertyType(),
			[PropertyTable::TYPE_STRING, PropertyTable::TYPE_NUMBER],
			true
		))
		{
			// it's ok to have duplicates for this type
		}
		else
		{
			// check for duplicates and skip ot
			/** @var Collection $collection */
			$collection = $this->get($fieldName);

			// we need filled collection to check value in it
			if (empty($collection) || !$collection->sysIsFilled())
			{
				$collection = $this->fill($fieldName);
			}

			foreach ($collection as $refObject)
			{
				// we have original scalar in VALUE
				if ($refObject->get('VALUE') === $remoteObject->get('VALUE'))
				{
					// skip duplicate
					return false;
				}
			}
		}
	}

	return parent::sysAddToCollection($fieldName, $remoteObject);
}