重命名的属性没有在 symfony 中正确保存

问题描述 投票:0回答:2

我正在尝试更新我的实体的属性。例如,在 TestEntity 类中:

class TestEntity
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    private ?string $testMe = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getTestMe(): ?string
    {
        return $this->testMe;
    }

    public function setTestMe(string $testMe): self
    {
        $this->testMe = $testMe;

        return $this;
    }
}

我在 snake_case 命名约定上犯了一个错误,我想将 $testMe 属性重命名为 $test_me。”

在更新的文本中,我对大写和标点符号进行了一些更正,并为清楚起见对文本的某些部分进行了改写。

“我在 TestEntity 类中到处都将 $testMe 属性重命名为 $test_me:

class TestEntity
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    private ?string $test_me = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getTestMe(): ?string
    {
        return $this->test_me;
    }

    public function setTestMe(string $test_me): self
    {
        $this->test_me = $test_me;

        return $this;
    }
}

但是,更新代码后,我注意到新旧属性都在数组中返回(使用 API 平台):

[
  {
      "test_me": "test",
      "testMe": "test",
      
    }
]

我已经清除了缓存和Doctrine缓存,项目中testMe除了TestEntity类中的getter和setter方法没有其他使用。我不确定旧财产被保存在哪里以及为什么。你能帮我理解这个问题吗?”

我的 composer.json 来查看我安装的 Bundles

{
  "type": "project",
  "license": "proprietary",
  "minimum-stability": "stable",
  "prefer-stable": true,
  "require": {
    "php": ">=8.1",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "api-platform/core": "^3.1",
    "doctrine/annotations": "^2.0",
    "doctrine/doctrine-bundle": "^2.8",
    "doctrine/doctrine-migrations-bundle": "^3.2",
    "doctrine/orm": "^2.14",
    "easycorp/easyadmin-bundle": "*",
    "lexik/jwt-authentication-bundle": "^2.18",
    "nelmio/cors-bundle": "^2.3",
    "phpdocumentor/reflection-docblock": "^5.3",
    "phpstan/phpdoc-parser": "^1.16",
    "sensio/framework-extra-bundle": "*",
    "symfony/apache-pack": "^1.0",
    "symfony/asset": "6.2.*",
    "symfony/console": "6.2.*",
    "symfony/debug-bundle": "6.2.*",
    "symfony/doctrine-messenger": "6.2.*",
    "symfony/dotenv": "6.2.*",
    "symfony/expression-language": "6.2.*",
    "symfony/flex": "^2",
    "symfony/framework-bundle": "6.2.*",
    "symfony/http-client": "6.2.*",
    "symfony/mailer": "6.2.*",
    "symfony/messenger": "6.2.*",
    "symfony/monolog-bundle": "*",
    "symfony/notifier": "6.2.*",
    "symfony/property-access": "6.2.*",
    "symfony/property-info": "6.2.*",
    "symfony/runtime": "6.2.*",
    "symfony/security-bundle": "6.2.*",
    "symfony/sendgrid-mailer": "6.2.*",
    "symfony/serializer": "6.2.*",
    "symfony/twig-bundle": "6.2.*",
    "symfony/validator": "6.2.*",
    "symfony/web-profiler-bundle": "6.2.*",
    "symfony/yaml": "6.2.*",
    "symfonycasts/verify-email-bundle": "*",
    "twig/extra-bundle": "*",
    "twig/twig": "^2.12|^3.0"
  },
  "config": {
    "allow-plugins": {
      "php-http/discovery": true,
      "symfony/flex": true,
      "symfony/runtime": true
    },
    "sort-packages": true
  },
  "autoload": {
    "psr-4": {
      "App\\": "src/"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "App\\Tests\\": "tests/"
    }
  },
  "replace": {
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php72": "*",
    "symfony/polyfill-php73": "*",
    "symfony/polyfill-php74": "*",
    "symfony/polyfill-php80": "*",
    "symfony/polyfill-php81": "*"
  },
  "scripts": {
    "auto-scripts": {
      "cache:clear": "symfony-cmd",
      "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
      "@auto-scripts"
    ],
    "post-update-cmd": [
      "@auto-scripts"
    ]
  },
  "conflict": {
    "symfony/symfony": "*"
  },
  "extra": {
    "symfony": {
      "allow-contrib": false,
      "require": "6.2.*"
    }
  },
  "require-dev": {
    "symfony/maker-bundle": "^1.48"
  }
}

php symfony doctrine
2个回答
0
投票

学说缓存中可能包含有关实体的过时信息。在这种情况下,您可以尝试通过在控制台中运行以下命令来清除学说缓存

php bin/console doctrine:cache:clear-metadata

此命令删除所有条令元数据缓存文件,允许条令使用最新信息重建缓存。


© www.soinside.com 2019 - 2024. All rights reserved.