why is that

$this->findOneBy(['cityId' => $id]); 

in reply

 Unrecognized field: $cityId 

however in Entity

  /** * @var integer * * @ORM\Column(name="city_id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $cityId; 
  • Maybe `$ this-> findOneBy (['city_id' => $ id]);`? - Andrewus
  • Nope same error Unrecognized field: city_id - Nikita Rassamahin
  • what's in the table? did the migration work? - Naumov
  • Everything is. It worked a long time ago. It was possible to solve the problem as follows, deleted $ this-> findOneBy (['city_id' => $ id]); leaving the repository empty called the magic symfony method this-> findOneByCityId ($ id) it worked fine, but why I didn’t work myself - Nikita Rassamahin

1 answer 1

The key in the transmitted array should be the name of the column in the table, but not the name of the variable. Try this:

  $this->findOneBy(['city_id' => $id]); 
  • Nope same error Unrecognized field: city_id - Nikita Rassamahin
  • Do you physically have this column in your database? After generating the entity, you ran the app bin / console doctrine: schema: update --force? - kover-samolet
  • Yes and Yes. I managed to solve the problem in the following way, deleted $this->findOneBy(['city_id' => $id]); leaving the repository empty caused the magic Symfony method this->findOneByCityId($id) work, it worked fine, but I can’t understand why the self-written one doesn't work - Nikita Rassamahin