【发布时间】:2021-08-31 16:36:45
【问题描述】:
我已经更改了我的 Symfony 项目的配置,以便在我的实体中使用 PHP 属性和 Doctrine。我对此感到非常高兴,并想尝试一下。
我已将我的 doctrine.yaml 从 annotation 更改为 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