【问题标题】:Only annotation mapping is supported by Maker BundleMaker Bundle 仅支持注解映射
【发布时间】:2021-08-31 16:36:45
【问题描述】:

我已经更改了我的 Symfony 项目的配置,以便在我的实体中使用 PHP 属性和 Doctrine。我对此感到非常高兴,并想尝试一下。

我已将我的 doctrine.yamlannotation 更改为 attribute

 orm:
    auto_generate_proxy_classes: true
    naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
    auto_mapping: true
    mappings:
        App:
            is_bundle: false
            type: attribute
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App

并在我的实体中使用属性

#[ORM\Entity(UserRepository::class)]
class User implements UserInterface
{
    #[ORM\Id()]
    #[ORM\GeneratedValue()]
    #[ORM\Column(type: "integer")]
    private ?int $id;

    #[ORM\Column(type: "string", length: 180, unique: true)]
    private ?string $email;

    #[ORM\Column(type: "json")]
    private array $roles = [];
}

使用此配置,我的php bin/console do:sc:up -f 运行良好。

但是当我尝试使用php bin/console make:entity 生成一个新实体时,我收到了这个错误:

[错误] make:entity 只支持注解映射,但是 App\Entity\Toto 类使用不同的 格式。如果您希望此命令生成属性和 getter/setter 方法,请添加您的映射
配置,然后使用 --regenerate 标志重新运行此命令。

似乎还不能使用 maker 来生成具有属性的实体。 有没有人找到解决此问题的方法,还是我们只需要等待新版本?

目前我正在使用:

"doctrine/annotations": "1.13.1"
"doctrine/doctrine-bundle": "2.4.2",
"doctrine/orm": "2.9.3"
"symfony/maker-bundle": "1.31.1",

【问题讨论】:

    标签: php symfony doctrine-orm php-8


    【解决方案1】:

    目前不支持。有 an issue 创建了这个要求,尽管我 120% 确定开发人员已经了解 PHP 属性,并且此功能将尽可能完成。

    与此同时,您可以手动创建实体,而无需使用 maker(不是那么难),甚至可以使用 Rector 之类的东西将注释转换为属性。有a built-in rule

    【讨论】:

      猜你喜欢
      • 2021-06-18
      • 2022-12-22
      • 2018-04-10
      • 2011-07-03
      • 1970-01-01
      • 2021-09-17
      • 2022-11-08
      • 1970-01-01
      • 2021-12-14
      相关资源
      最近更新 更多