原则 - 引用的列名称"id"必须是目标实体类上的主键列



我在验证和架构创建方面遇到问题,错误日志是:

[Mapping]  FAIL - The entity-class 'AppApiEntityUser' mapping is invalid:
* The referenced column name 'id' has to be a primary key column on the target entity class 'AppAcmeEntityUserBaseUser'.
* The join columns of the association 'createdBy' have to match to ALL identifier columns of the target entity 'AppAcmeEntityUserBaseUser', however '' are missing.
* The referenced column name 'id' has to be a primary key column on the target entity class 'AppAcmeEntityUserBaseUser'.
* The join columns of the association 'modifiedBy' have to match to ALL identifier columns of the target entity 'AppAcmeEntityUserBaseUser', however '' are missing.

我正在使用Symfony 4,但我有继承问题

src/Acme/Entity/Base/BaseUser.php

<?php
namespace AppAcmeEntityUser;
use DoctrineORMMapping as ORM;
use SymfonyComponentSecurityCoreUserUserInterface;
use SymfonyComponentValidatorConstraints as Assert;
use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;
/**
 * @ORMMappedSuperclass
 * @UniqueEntity("email")
 * Class Document
 */
class BaseUser implements UserInterface, Serializable
{
/**
 * @var int The id
 *
 * @ORMId
 * @ORMGeneratedValue
 * @ORMColumn(type="integer")
 */
protected $id;
/**
 * @var BaseUser
 * @ORMManyToOne(targetEntity="AppAcmeEntityUserBaseUser")
 * @ORMJoinColumn(name="created_by", referencedColumnName="id")
 */
protected $createdBy;
/**
 * @var BaseUser
 * @ORMManyToOne(targetEntity="AppAcmeEntityUserBaseUser")
 * @ORMJoinColumn(name="modified_by", referencedColumnName="id")
 */
protected $modifiedBy;
public function __construct( BaseUser $user)
{
    $this->createdBy    = $user;
    $this->modifiedBy   = $user;
}

/**
 * @return int
 */
public function getId(): int
{
    return $this->id;
}
/**
 * @param int $id
 */
public function setId(int $id)
{
    $this->id = $id;
}

并且有一个实体试图扩展此基本用户

src/Api/Entity/Base/User.php

<?php
namespace AppApiEntity;
use AppAcmeEntityUserBaseUser;
use DoctrineORMMapping as ORM;
/**
 * @ORMEntity
 */
class User extends BaseUser  { ... }

问题出在某处

/**
 * @var BaseUser
 * @ORMManyToOne(targetEntity="AppAcmeEntityUserBaseUser")
 * @ORMJoinColumn(name="created_by", referencedColumnName="id")
 */
protected $createdBy;
/**
 * @var BaseUser
 * @ORMManyToOne(targetEntity="AppAcmeEntityUserBaseUser")
 * @ORMJoinColumn(name="modified_by", referencedColumnName="id")
 */
protected $modifiedBy;

当我删除它们时,一切正常。

我的映射文件配置/包/doctrine.yaml

doctrine:
dbal:
    # With Symfony 3.3, remove the `resolve:` prefix
    url: '%env(DATABASE_URL)%'
orm:
    auto_generate_proxy_classes: '%kernel.debug%'
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true
    mappings:
        Api:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Api/Entity'
            prefix: 'AppApiEntity'
            alias: Api
        Acme:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Acme/Entity'
            prefix: 'AppAcmeEntity'
            alias: Acme

你能帮忙吗?

更改为

 /**
 * @var int
 *
 * @ORMId
 * @ORMGeneratedValue(strategy="AUTO")
 * @ORMColumn(type="integer")
 */
private $id;

检查目标实体命名空间。捆绑包在哪里...部分 Symfony Bundle Name Doc

/**
* @var BaseUser
* @ORMManyToOne(targetEntity="yourBaseUser")
* @ORMJoinColumn(name="created_by", referencedColumnName="id")
*/
protected $createdBy;
/**
* @var BaseUser
* @ORMManyToOne(targetEntity="yourBaseUser")
* @ORMJoinColumn(name="modified_by", referencedColumnName="id")
*/
protected $modifiedBy;

相关内容

  • 没有找到相关文章

最新更新