Symfony 2与失踪ID的OneToOne关系

时间:2015-11-19 16:52:41

标签: symfony orm doctrine one-to-one relationships

首先,这个Symfony是2.7.6版本,bbdd是mysql。

我的问题是我的" oneToOne"关系失败。失败,因为我的tech_note_en没有#34;父亲"。我想,用一点代码会更好......

简历:One" tech_note"有一个" tech_note_es",一个" tech_note_en"和一个" tech_note_fr",......

TECH_NOTE

class Tech_note {
    /**
     * @ORM\OneToOne(targetEntity="Tech_note_es", mappedBy="tech_note", cascade={"persist", "remove"})
     * */
    private $tech_note_es;
}

TECH_NOTE_ES

class Tech_note_es {
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\OneToOne(targetEntity="Tech_note", inversedBy="tech_note_es")
     * @ORM\JoinColumn(name="tech_note_id", referencedColumnName="id")
     */
    private $tech_note;
}

一切都好,但是当我让'#34;坚持"我有这样的事情:

Tech_note
   id
  5236

Tech_note_es
id    | tech_note_id
224   |   NULL

如果我更改5236的null,则一切正常。但我认为这个ID是由学说/ orm提供的,不是吗?或者我错了,我需要使用" setters / getters"在我的控制器动作中手动建立关系?

class Tech_note {
    /**
     * Set techNoteEs
     *
     * @param \AppBundle\Entity\Tech_note_es $techNoteEs
     *
     * @return Tech_note
     */
    public function setTechNoteEs(\AppBundle\Entity\Tech_note_es $techNoteEs = null) {
        $techNoteEs->setTechNote($this);
        $this->tech_note_es = $techNoteEs;

        return $this;
    }

    /**
     * Set techNoteEn
     *
     * @param \AppBundle\Entity\Tech_note_en $techNoteEn
     *
     * @return Tech_note
     */
    public function setTechNoteEn(\AppBundle\Entity\Tech_note_en $techNoteEn = null) {
        $techNoteEn->setTechNote($this);
        $this->tech_note_en = $techNoteEn;

        return $this;
    }

    /**
     * Set techNoteFr
     *
     * @param \AppBundle\Entity\Tech_note_fr $techNoteFr
     *
     * @return Tech_note
     */
    public function setTechNoteFr(\AppBundle\Entity\Tech_note_fr $techNoteFr = null) {
        $techNoteFr->setTechNote($this);
        $this->tech_note_fr = $techNoteFr;

        return $this;
    }

}

感谢所有人!

罗杰

0 个答案:

没有答案