Answer the question
In order to leave comments, you need to log in
Deal with Doctrine?
There are two entities. The relationship between them is one to many.
#obj1
manyToOne:
post:
targetEntity: Site\DeskBundle\Entity\Post
cascade:
- persist
inversedBy: dogs
joinColumns:
post_id:
referencedColumnName: id
#obj2
oneToMany:
dogs:
targetEntity: Site\DeskBundle\Entity\Dog
mappedBy: post
$post = $form->getData()->setAddDate();<br>
$dogs = $post->getDogs();<br>
if (!empty($dogs)) {<br>
$em = $this->getDoctrine()->getManager();<br>
$em->persist($post);<br>
foreach ($dogs as $dog) {<br>
$dog->setPost($post);<br>
$em->persist($dog);<br>
}<br>
$em->flush();<br>
}<br>
cascade - persist
, but errors fly out, I can tell you which ones. var template = {<br>
code: '{{ form_widget(form.dogs.vars.prototype) }}',<br>
count: 0,<br>
max: 6<br>
};<br>
function addDog(obj) {<br>
var dogs = document.getElementById("add_dog_place");<br>
template.count++;<br>
if (template.count < template.max) {<br>
var dog = document.createElement("li");<br>
dog.innerHTML = template.code.split('__name__').join(template.count.toString());<br>
dogs.appendChild(dog);<br>
} else {<br>
obj.setAttribute("disable", "true");<br>
}<br>
}<br>
Answer the question
In order to leave comments, you need to log in
1. How do you create a form? If you slip a clean model on it, everything should be saved automatically.
2. The question is not entirely clear. You select a post and do ->getDogs() for it. How do you plan to use this data
3. We use the method described in the documentation: symfony.com/doc/master/cookbook/form/form_collections.html
PS: add errors under the spoiler
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question