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

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

		if ($valueObject->sysHasPrimary())
		{
			// existing object. nothing to do, just call parent remove
			$remoteObject = $valueObject;
		}
		else
		{
			// find relation object by value and remove it
			/** @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);
			}

			$foundValue = false;

			foreach ($collection as $refObject)
			{
				// find original object with that value
				if ($valueObject->get('VALUE') === $refObject->get('VALUE'))
				{
					$foundValue = true;
					$remoteObject = $refObject;
					break;
				}
			}

			if (!$foundValue)
			{
				// nothing to do, value was not found in collection
				return false;
			}
		}
	}

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