donglv5269 2018-11-08 16:14
浏览 49

Symfony 4:Doctrine with manyToOne join

I trying Symfony 4 for "fun". And for that I try to rewrite an old website without framework as the moment, with Symfony 4.

For that I configure my app on my database with existing datas. And I'd make login form.

BUT on my User classe, I have some colomn who make me some issues.

See bellow my user's class's annotations:

/**
 * Utilisateur
 *
 * @ORM\Table(name="utilisateur", uniqueConstraints={@ORM\UniqueConstraint(name="mail", columns={"mail"})}, indexes={@ORM\Index(name="FK_UTILISATEUR_idDroit", columns={"idDroit"})})
 * @ORM\Entity
 */

and my user's struct :

idutilisateur
nom
prenom
mail
password
dateinscription
datevalidation
token
iddroit
plainPassword

Like you can see, I create before iddroit as foreign key of droit's table. Doctrine generated the propertie as

    /**
     * @var Droit
     *
     * @ORM\ManyToOne(targetEntity="Droit")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="idDroit", referencedColumnName="idDroit")
     * })
     */
    private $iddroit;

And created the getter as

    public function getIddroit(): Droit
    {
        return $this->iddroit;
    }

And after followed the documentation about registration / login, the debugger respond =>

Return value of App\Entity\Utilisateur::getIddroit() must be an instance of App\Entity\Droit, null returned

So I imagine he want an object and not just an ID, even if in anotation it's making the Join rules. Any ID what's happened ?

And I understand to return an objet, but I have no idea how to return that.

If any suggestion.

Thanks guys ;)

Laurent

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线