【问题标题】:Duplicate definition of column 'random_id' on entity 'Acme\ApiBundle\Entity\Client' in a field or discriminator column mapping字段或鉴别器列映射中实体“Acme\ApiBundle\Entity\Client”上列“random_id”的重复定义
【发布时间】:2025-12-20 08:35:12
【问题描述】:

我创建了扩展 FOSOAuthServerBundle 的客户端。这个客户端的代码如下:

<?php 
namespace Acme\ApiBundle\Entity;
use FOS\OAuthServerBundle\Entity\Client as BaseClient;
use Doctrine\ORM\Mapping as ORM;
 /**
 * Class Client
 *
 * @package Acme\ApiBundle\Entity
 *
 * @ORM\Table("oauth2_clients")
 * @ORM\Entity
 */
class Client extends BaseClient
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;
    protected $name;

    public function __construct()
    {
        parent::__construct();
    }
    public function setName($name)
    {
        $this->name = $name;
    }
    public function getName()
    {
        return $this->name;
   }
}

所以,正如我所说,我扩展了具有 $randomId 的 FOSOAuthServerBundle(\friendsofsymfony\oauth-server-bundle\Entity\Client.php,第 28 行)。现在我得到一个错误:

MappingException.php 第 565 行中的 MappingException: 字段或鉴别器列映射中实体“Acme\ApiBundle\Entity\Client”上列“random_id”的重复定义。

我哪里做错了?

【问题讨论】:

    标签: php oauth-2.0 symfony fosoauthserverbundle


    【解决方案1】:

    当我使用FOS\OAuthServerBundle\Entity\Client 时,我使用了一个扩展另一个目标类 (FOS\OAuthServerBundle\Model\Client) 的类。有目标变量,例如我发现重复的 $RandomId。所以,根据我的观点,当Acme\ApiBundle\Entity\Client 扩展FOS\OAuthServerBundle\Entity\Client 扩展FOS\OAuthServerBundle\Model\Client 时,我们得到了两次变量而不是一次。所以我决定直接扩展FOS\OAuthServerBundle\Model\Client,它解决了我的问题。谁能解释一下为什么不能以这种方式编写代码?

    【讨论】:

      最近更新 更多