I have the essence of skill and language, specialty, the essence of the platform with the ManyToMany relationship, and when I create the skill, I select the language, specialty, platforms and form, and the normal ones are stored and hidden in the database. But when I create a language, specialty or platform, I have a mistake. This value is also invalid on the debug panel in the form. Why I do not understand, please help:
Message Origin Cause
This value is not valid. skills Symfony\Component\Validator\ConstraintViolation
Object(Symfony\Component\Form\Form).children[skills] = [0 => AngularJS, 1 => API]
Caused by:
Symfony\Component\Form\Exception\TransformationFailedException
Unable to reverse value for property path "skills": Could not find all matching choices for the given values
Caused by:
Symfony\Component\Form\Exception\TransformationFailedException
Could not find all matching choices for the given values
In objects I delete
public function __construct()
{
$this->language = new \Doctrine\Common\Collections\ArrayCollection();
$this->platforms = new \Doctrine\Common\Collections\ArrayCollection();
$this->specialities = new \Doctrine\Common\Collections\ArrayCollection();
}
as well as language, specialty, platforms are also deleted
objects:
class Skill
{
use Timestampable;
private $id;
protected $language;
protected $platforms;
protected $specialities;
and example:
class CodeDirectorySpecialities
{
use Timestampable;
private $id;
private $specialities;
protected $skills;
and add to all objects
public function __toString()
{
return $this->string_filed_entity;
}
this is my form
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('specialities');
$builder->add('skills','entity',
array(
'class'=>'MyBundle\Entity\Skill',
'property'=>'skill',
'multiple'=>true,
'expanded' => true,
)
);
}
and action
$entity = new CodeDirectorySpecialities();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$skills = $entity->getSkills()->getValues();
if(!empty($skills)){
foreach($skills as $skill){
$skill->addSpeciality($entity);
$em->persist($skill);
}
}
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('specialities_show', array('id' => $entity->getId())));
}