The application has thrown an exception!
Doctrine\ORM\ORMInvalidArgumentException
A new entity was found through the relationship 'Core\Model\Filter#category' that was not configured to cascade persist operations for entity: Core\Model\Category@00000000314fc99200005639c0395a5e. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Core\Model\Category#__toString()' to get a clue.
This function cause an exception. Some comits in code. It is ZendFramework 2.
protected function handleCategory( $data, \Core\Model\Project $project )
{
$filter = $this->sl()->get( "Core\Filter\JSON\Category" );
$filter->setData( $data );
if( !$filter->isValid() ){
$id = @$data[ 'id' ];
$report = array(
'id' => $id,
'messages' => $filter->getMessages()
);
return $report;
}
$filteredData = $filter->getValues();
$repo = $this->em()->getRepository( "Core\Model\Category" );
$category = $repo->findOneBy(
array(
'id' => $filteredData[ 'id' ],
'project' => $project->getId()
)
);
$b = false;
if( !$category ){
$b = true;
$category = new \Core\Model\Category;
$category->setProject( $project )
->setCreatedAt( new \DateTime() );
}
$category->setUpdatedAt( new \DateTime() );
/* Hydrate Category */
$hydrator = $this->sl()->get( "Core\Hydrator\JSON\Category" );
$hydrator->hydrate( $filteredData, $category );
/* Persist Category */
$this->em()->persist($category);
if($b)
{
/* Return Filter Data */
$filterData = $hydrator->get();
/* Hydrate Filter */
$filterHydrator = $this->sl()->get( 'Core\Hydrator\JSON\Filter' );
//$filtersObj = array();
foreach($filterData as $i => $fdata)
{
$filterObj = new \Core\Model\Filter;
$filterObj->setProject($project)->setCategory($category);
$filterHydrator->hydrate($fdata, $filterObj);
$this->em()->persist($filterObj);
/*Breaks after any flush after second persist*/
$this->em()->flush();
}
}
return true;
}
I tried to solve this problem by:
- MERGE, but get another exception, A managed dirty+entity [...]
- cascade={"persist"}, but nothing happend.
- rewrite code in that what you see, i made all persists in one function one by one with one EntityManager.(If i missing something please tell me)
Never work before with ZendFramework. I love Symfony with app/console manager, all entities with tables creates authomatically.