我的下一個關係:實體沒有關聯正確
Presupuesto: oneToMany with Revision
Revision: oneToMany with Capitulo
Capitulo: oneToMany with Requisito
Requisito: oneToMany with Articulo
我有嵌入式與這些實體和「addTagForm」集的形式。問題是,當我提交表單時,除Revision
和Capitulo
之外的所有內容都正確關聯,該關聯關聯爲空。
下面有關於這兩個實體最相關的信息:
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;
}
Capitulo.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;
}
nuevo.html.twig
{{ form_start(formulario) }}
//some code..
{% include 'ComercialBundle:Presupuesto:listaRevisiones.html.twig' %}
//some code..
{{ form_end(formulario) }}
l istaRevisiones.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>
我想不通爲什麼revision_id
爲空。有任何想法嗎?謝謝
你能在你的控制器檢查,如果在表單中的數據實際上是設置正確。因此,這將是'var_dump()':'$ form-> getData() - > getRevisions() - > getCapitulos();'。 這樣我們可以找出問題出在表單聲明還是在Doctrine中。 –
是的,當我做轉儲($ form-> getData())時,Capitulo出現,但其版本屬性爲null –