Symfony2,Doctrine,关系中的空实体

时间:2013-02-04 21:38:30

标签: symfony doctrine entity

我有两个实体,一个是主要的,第二个是附加的,它们作为OneToOne加入。我不会全部展示,我认为没有必要:

apiKey

/**
 * @ORM\OneToOne(targetEntity="Eve\ApiBundle\Entity\Account\apiKeyInfo", inversedBy="apiKey_byKeyID")
 * @ORM\JoinColumn(name="keyID", referencedColumnName="keyID")
 */
private $apiKeyInfo_byKeyID;

public function get_apiKeyInfo_byKeyID()
{
    return $this->apiKeyInfo_byKeyID;
}

apiKeyInfo

/**
 * @ORM\OneToOne(targetEntity="Eve\ProfileBundle\Entity\apiKey", mappedBy="apiKeyInfo_byKeyID")
 */
private $apiKey_byKeyID;

public function get_apiKey_byKeyID()
{
    return $this->apiKey_byKeyID;
}


/**
 * @ORM\Column(name="type", type="string", length=255)
 */
private $type;


/**
 * @param string $type
 * @return apiKeyInfo
 */
public function setType($type)
{
    $this->type = $type;

    return $this;
}

/**
 * @return string 
 */
public function getType()
{
    return $this->type;
}

我在twig中调用的关系(apiKey在php部分中得到)

apiKey.get_apiKeyInfo_byKeyID.type

当db表充满数据时,它工作正常,但是当“apiKeyInfo”表没有相同的keyID时,它会抛出异常:

Entity was not found. 

我理解为什么,因为它找不到具有相同keyID的条目......但我不知道如何处理它。

所以问题是...... 我怎样才能使这种关系的结果为空?

1 个答案:

答案 0 :(得分:0)

麻烦在于对实体的错误描述。问题解决了。

相关问题