Revision null when sending the form

3

I have a form with several embeds. I have the Budget entity, which has oneToMany relation with Revision, and revision has oneToMany with Chapter, Chapter has also oneToMany with another call Requirement, but it is not necessary to inquire more since my problem is between Chapter and Requirement. I do not know why, when I add a chapter with addTagForm and it is filled with everything, sending the form seems to have gone well, but to my surprise all the relationships have been linked less with Revision Chapter, I made a dump before doing the persist of budget, and I have found that when I navigate in the dump until I get to the Chapter, the revision_id attribute is set to null. Any ideas? Below I leave you fragments of code that I consider most relevant:

Revision.php

/**
 * @ORM\OneToMany(targetEntity="CeiferIT\ComercialBundle\Entity\Capitulo", mappedBy="revision", cascade={"persist"}, orphanRemoval=true)
 */
protected $capitulos;

/**
 * @param \CeiferIT\ComercialBundle\Entity\Capitulo $capitulo
 *
 * @return Revision
 */
public function addCapitulo(\CeiferIT\ComercialBundle\Entity\Capitulo $capitulo)
{
    $capitulo->setRevision($this);
    $this->capitulos[] = $capitulo;

    return $this;
}

/**
 * @param \CeiferIT\ComercialBundle\Entity\Capitulo $capitulo
 */
public function removeCapitulo(\CeiferIT\ComercialBundle\Entity\Capitulo $capitulo)
{
    $this->capitulos->removeElement($capitulo);
}

/**
 * @return \Doctrine\Common\Collections\Collection
 */
public function getCapitulos()
{
    return $this->capitulos;
}

Chapter.php

/**
 * @ORM\ManyToOne(targetEntity="CeiferIT\ComercialBundle\Entity\Revision", inversedBy="capitulos", cascade={"persist"})
 * @ORM\JoinColumn(name="revision_id", referencedColumnName="id")
 */
private $revision;

/**
 * @param \CeiferIT\ComercialBundle\Entity\Revision $revision
 *
 * @return Capitulo
 */
public function setRevision(\CeiferIT\ComercialBundle\Entity\Revision $revision = null)
{
    $this->revision = $revision;
    return $this;
}

/**
 * @return \CeiferIT\ComercialBundle\Entity\Revision
 */
public function getRevision()
{
    return $this->revision;
}

new.html.twig

{{ form_start(formulario) }}
//some code..
{% include 'ComercialBundle:Presupuesto:listaRevisiones.html.twig' %}
//some code..
{{ form_end(formulario) }}

listaRevisiones.html.twig

{% macro information_prototype(revision) %}
    {% if form_errors(revision.total) %}
        {{ form_widget(revision.total, {'attr': {'class': 'form-control totalrevision error'}}) }}
    {% else %}
        {{ form_widget(revision.total, {'attr': {'class': 'form-control totalrevision'}}) }}
    {% endif %}
    {% include 'ComercialBundle:Presupuesto:listacapitulos.html.twig' %}
{% endmacro %}

<div class="ibox product-box active primerarevision" data-prototype="{{ _self.information_prototype(formulario.revisiones.vars.prototype)|e}}">
{% for revision in formulario.revisiones %}
    {{ _self.information_prototype(revision)}}
{% endfor %}
</div>
    
asked by Ivan Javier Barranco Gavilan 23.02.2016 в 14:51
source

1 answer

1

Did you check the schema?

app/console doctrine:schema:validate

When the mapping generates error, the forms do not work correctly with the relationships; In addition, one usually uses a function in the 'OneToMany' function

public function __toString() 
{
    return $StringQueUsarasDeRetorno;
}

With this function, you indicate to the form what to contribute in the field of the form that presents the relationship

    
answered by 17.03.2016 в 14:17