<commit_before><?php

/**
 * This file is part of the Nextras\ORM library.
 *
 * @license    MIT
 * @link       https://github.com/nextras/orm
 * @author     <NAME>
 */

namespace Nextras\Orm\Relationships;

use Nette\NotImplementedException;
use Nextras\Orm\Entity\IEntity;
use Nextras\Orm\NotSupportedException;


class OneHasMany extends HasMany
{

	public function persist($recursive = TRUE)
	{
		foreach ($this->toAdd as $add) {
			$this->getTargetRepository()->persist($add);
		}

		foreach ($this->toRemove as $remove) {
			$this->getTargetRepository()->persist($remove);
		}

		if ($this->collection !== NULL) {
			foreach ($this->collection as $entity) {
				$this->getTargetRepository()->persist($entity);
			}
		}

		$this->isModified = FALSE;
		$this->toRemove = $this->toAdd = [];
		if ($this->collection && $this->collection->getRelationshipMapper() === NULL) {
			$this->collection = NULL;
		}
	}


	public function getInjectedValue()
	{
		throw new NotSupportedException();
	}


	public function getStorableValue()
	{
		return NULL;
	}


	public function getRawValue()
	{
		throw new NotImplementedException();
	}


	protected function createCollection()
	{
		return $this->getTargetRepository()->getMapper()->createCollectionOneHasMany($this->metadata, $this->parent);
	}


	protected function updateRelationshipAdd(IEntity $entity)
	{
		$this->updatingReverseRelationship = TRUE;
		$entity->{$this->metadata->relationshipProperty} = $this->parent;
		$this->updatingReverseRelationship = FALSE;
	}


	protected function updateRelationshipRemove(IEntity $entity)
	{
		$this->updatingReverseRelationship = TRUE;
		$entity->{$this->metadata->relationshipProperty} = NULL;
		$this->updatingReverseRelationship = FALSE;
	}

}<commit_msg>[relationships] fixed some weird PHP bug, when magic methods wasn't triggered<commit_after><?php

/**
 * This file is part of the Nextras\ORM library.
 *
 * @license    MIT
 * @link       https://github.com/nextras/orm
 * @author     <NAME>
 */

namespace Nextras\Orm\Relationships;

use Nette\NotImplementedException;
use Nextras\Orm\Entity\IEntity;
use Nextras\Orm\NotSupportedException;


class OneHasMany extends HasMany
{

	public function persist($recursive = TRUE)
	{
		foreach ($this->toAdd as $add) {
			$this->getTargetRepository()->persist($add);
		}

		foreach ($this->toRemove as $remove) {
			$this->getTargetRepository()->persist($remove);
		}

		if ($this->collection !== NULL) {
			foreach ($this->collection as $entity) {
				$this->getTargetRepository()->persist($entity);
			}
		}

		$this->isModified = FALSE;
		$this->toRemove = $this->toAdd = [];
		if ($this->collection && $this->collection->getRelationshipMapper() === NULL) {
			$this->collection = NULL;
		}
	}


	public function getInjectedValue()
	{
		throw new NotSupportedException();
	}


	public function getStorableValue()
	{
		return NULL;
	}


	public function getRawValue()
	{
		throw new NotImplementedException();
	}


	protected function createCollection()
	{
		return $this->getTargetRepository()->getMapper()->createCollectionOneHasMany($this->metadata, $this->parent);
	}


	protected function updateRelationshipAdd(IEntity $entity)
	{
		$this->updatingReverseRelationship = TRUE;
		$entity->setValue($this->metadata->relationshipProperty, $this->parent);
		$this->updatingReverseRelationship = FALSE;
	}


	protected function updateRelationshipRemove(IEntity $entity)
	{
		$this->updatingReverseRelationship = TRUE;
		$entity->setValue($this->metadata->relationshipProperty, NULL);
		$this->updatingReverseRelationship = FALSE;
	}

}
{'fraction_non_alphanumeric': 0.14429530201342283, 'fraction_numerical': 0.0, 'mean_word_length': 4.511556240369799, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 71, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '647146', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1093, 'n_words': 214}