0

我正在尝试创建 oneToMany 关系。由于 Doctrine 仅提供 ManyToOne 单向 im 使用它。不知何故,映射验证失败,我无法发现我的错误:

验证错误:

[映射] FAIL - 实体类 'Strego\TippBundle\Entity\BetRound' 映射无效:* 关联 Strego\TippBundle\Entity\BetRound#userStatus 指的是拥有方字段 Strego\TippBundle\Entity\UserBetRoundStatus#betRound 哪个不存在。

我的第一个实体(BetRound):

<?php 
namespace Strego\TippBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Doctrine\Common\Collections\Collection as Collection;
use Strego\AppBundle\Entity\Base as BaseEntity;


/**
 * Strego\TippBundle\Entity\BetRound
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class BetRound extends BaseEntity {

    //......

    /**
     *
     * @var Collection
     * @ORM\OneToMany(targetEntity="UserBetRoundStatus", mappedBy="betRound", cascade={"all"})
     */
    protected $userStatus;

}

我的相关实体(UserBetRoundStatus)

<?php
namespace Strego\TippBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Strego\AppBundle\Entity\Base as BaseEntity;

/**
 * Strego\TippBundle\Entity\Game
 *
 * @ORM\Table
 * @ORM\Entity
 * @UniqueEntity(fields={"user", "betRound"}, message="Unique Entity Validator Fails for UserStatus", groups="unique")
 * 
 */
class UserBetRoundStatus extends BaseEntity {
    // .....

    /*
     * @var BetRound
     * @ORM\ManyToOne(targetEntity="BetRound", inversedBy="userStatus")
     * @ORM\JoinColumn(name="betround_id", referencedColumnName="id", nullable=false)
     * @Assert\NotNull()
     */
    protected $betRound;
}
4

1 回答 1

2

我发现了问题:

/**  <---------  you need two *
 * @var BetRound
 * @ORM\ManyToOne(targetEntity="BetRound", inversedBy="userStatus")
 * @ORM\JoinColumn(name="betround_id", referencedColumnName="id", nullable=false)
 * @Assert\NotNull()
 */
protected $betRound;
于 2013-01-28T20:35:49.777 回答