symfony2与ManyToOne一起存在

时间:2016-10-23 15:36:46

标签: php symfony mapping

尝试保留对象,但是没有保存具有映射关系的字段profiel_id。对象的其余部分很奇怪。

$fotos = new Fotos();
$fotos->setProfielId($this->profielId);
$fotos->setNaam($file->name);
$fotos->setAanmaakDatum(time());
$fotos->setWijzigingDatum(time());
$fotos->setProfielfoto(0);       
// Save the object
$this->em->persist($fotos);
$this->em->flush();

fotos.xml

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-   mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Klik\CoreBundle\Entity\Fotos" table="fotos">
<indexes>
  <index name="profiel_id" columns="profiel_id"/>
</indexes>
<id name="id" type="integer" column="id">
  <generator strategy="IDENTITY"/>
</id>
<field name="profielId" type="integer" column="profiel_id" length="11" nullable="true"/>    
<field name="naam" type="string" column="naam" length="255" nullable="true"/>  
<field name="profielfoto" type="boolean" column="profielfoto" nullable="true"/>

<field name="aanmaakDatum" type="integer" column="aanmaak_datum" nullable="true"/>
<field name="wijzigingDatum" type="integer" column="wijziging_datum" nullable="true"/>
<field name="wijzigingGebruikerId" type="integer" column="wijziging_gebruiker_id" nullable="true"/>
<!-- many-to-one field="profiel" target-entity="Klik\CoreBundle\Entity\Profiel" / -->

<many-to-one field="profiel" target-entity="Klik\CoreBundle\Entity\Profiel" inversed-by="fotos" >
  <join-column name="profiel_id" referenced-column-name="id" />
</many-to-one>

  </entity>
</doctrine-mapping>

当我删除多对一声明时,一切都很好,profiel_id会被保存,但其他地方的其他内容会在我不想要的地方中断。

这是我的profiel.xml的一部分

 <one-to-many field="fotos" target-entity="Klik\CoreBundle\Entity\Fotos"  mapped-by="profiel" />

0 个答案:

没有答案