Kev*_*vin 5 php symfony doctrine-orm php-8
我已经更改了 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
Run Code Online (Sandbox Code Playgroud)
并在我的实体中使用属性
#[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 = [];
}
Run Code Online (Sandbox Code Playgroud)
有了这个配置,我的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",
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1754 次 |
| 最近记录: |