はじめに
doctrineを使っていて、以下のエラーがでてきた。
[2021-06-02 12:02:44] request.CRITICAL: Uncaught PHP Exception ErrorException: "Notice: Undefined index: <クラス名>" at /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 122 {"exception":"[object] (ErrorException(code: 0): Notice: Undefined index: <クラス名> at /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:122)"} []
TL;DR
以下のコマンドでdoctrineのスキーマ定義を確認する
php bin/console doctrine:schema:validate
以下のようなエラーが出てきました。
root@2043c465e73b:/var/www/html # php bin/console doctrine:schema:validate
Cannot load Xdebug - it was already loaded
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(
Mapping
-------
[FAIL] The entity-class App\Entity\NoticeLog mapping is invalid:
* The association App\Entity\NoticeLog#user refers to the inverse side field App\Entity\User#NoticeLog which does not exist.
[FAIL] The entity-class App\Entity\User mapping is invalid:
* The mappings App\Entity\User#noticeLogs and App\Entity\NoticeLog#user are inconsistent with each other.
Database
--------
[ERROR] The database schema is not in sync with the current mapping file.
そういえば、make:entityで作成した後、作り直したプロパティがあって、そのために不整合が起きた模様。
修正することで不具合がでなくなりました。
参考文献