skip to Main Content

I am trying to update the properties of my entity. For example, in the TestEntity class:

class TestEntity
{
    #[ORMId]
    #[ORMGeneratedValue]
    #[ORMColumn]
    private ?int $id = null;

    #[ORMColumn(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;
    }
}

I made a mistake with the snake_case naming convention, and I want to rename the $testMe property to $test_me."

In the updated text, I made some corrections to the capitalization and punctuation, and rephrased some parts of the text for clarity.

"I renamed the $testMe property to $test_me everywhere in the TestEntity class:

class TestEntity
{
    #[ORMId]
    #[ORMGeneratedValue]
    #[ORMColumn]
    private ?int $id = null;

    #[ORMColumn(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;
    }
}

However, after updating the code, i noticed that both the old and the new properties are being returned in an array (using API-Platform):

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

I have cleared the cache and Doctrine cache, and there is no other use of testMe in the project except for the getter and setter methods in the TestEntity class. I am not sure where the old property is being saved and why. Can you help me understand this issue?"

My composer.json to see my installed 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"
  }
}

2

Answers


  1. it is possible that the doctrine cache contains outdated information about the entity. In this case, you can try clearing the doctrine cache by running the following command in the console

    php bin/console doctrine:cache:clear-metadata
    

    This command removes all doctrine metadata cache files, allowing doctrine to rebuild the cache with the most recent information.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search