Reputation: 55
I have embed form, inside embed form there is an EntityType with multiple=> true. When i am saving to databse i get this: Doctrine\Common\Collections\ArrayCollection@000000...
When i change EntityType to CHoiceType with multiple=> true everything seems to be correct.
/**
* Set emotions
*
* @param simple_array $emotions
*
* @return Movies
*/
public function setEmotions($emotions) {
$this->emotions = $emotions;
return $this;
}
FormType
->add('emotions', EntityType::class, array(
'class' => 'MovieBundle:Emotions',
'multiple' => true,
'choice_label' => 'emotion',
))
I have no idea where the problem is. Is it something with embed form, or i need data transformer?
Upvotes: 1
Views: 783
Reputation: 2048
Whene you set multiple to true symfony set your attribute value into an array, if you set multiple to false this attribute will be set like it is so the difference between them is :
setEmotions(ArrayCollection $emotions)
, and it will be persisted one by one using a loop.setEmotions(Emotion $emotion)
and it will be persisted only the object that he get from getEmotions()
in this case he will persist only the DoctrineArrayCollection not the objects wrapped in it and this is the reason of your exceptionUpvotes: 1