OneToMany无效映射

时间:2013-01-28 17:34:36

标签: doctrine-orm

我正在尝试创建oneToMany关系。由于Doctrine仅提供ManyToOne Unidirectional即时通讯。不知何故,映射的验证失败了,我无法发现我的错误:

验证错误:

  

[Mapping] 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;
}

1 个答案:

答案 0 :(得分: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;