【问题标题】:OneToMany invalid MappingOneToMany 无效映射
【发布时间】:2013-01-28 17:34:36
【问题描述】:

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

验证错误:

[映射] 失败 - 实体类 '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;
}

【问题讨论】:

    标签: doctrine-orm


    【解决方案1】:

    我找到了问题:

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

    【讨论】:

      猜你喜欢
      • 2017-12-30
      • 2019-03-27
      • 1970-01-01
      • 2023-03-04
      • 2014-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多