0

i ve searched for 2 days for an answer but i can't find it, please help me guys ! :)

I Have this :

In Entity Bon:

/**
 * $entreprise.
 *
 * 
 *
 * @ORM\ManyToOne(targetEntity="Soraya\UserBundle\Entity\Entreprise", inversedBy="bons")
 * @ORM\JoinColumn(name="entreprise_id", referencedColumnName="id")
 */
private $entreprise;

And this in entity Entreprise :

/**
 * $bons.
 *
 * @ORM\OneToMany(targetEntity="Soraya\BonBundle\Entity\Bon", mappedBy="entreprise")
 */
protected $bons;

And here is my repo function:

 public function getEntrepriseBons($entreprise, $container = null)
{
    if ($container === null) {
        return null;
    }

    $queryBuilder = $this->_em->createQueryBuilder()
        ->select('bon')
        ->from('Soraya\BonBundle\Entity\Bon', 'bon')
        ->where('bon.entreprise = :entreprise')
        ->andWhere('bon.isDeleted = 0')
        ->setParameters(array('entreprise' => $entreprise,));

    return $queryBuilder->getQuery()->getResult();
}

And here is the error by Symfony :

[Semantical Error] line 0, col 58 near 'entreprise =': Error: Class Soraya\BonBundle\Entity\Bon has no field or association named entreprise

I have all getters and setters implemented in both classes, i updated entities (doctrine:schema:update).

I looked everywhere and all responses in other threads like this one, didnt helped me. what am i missing here ? Thank you guys!

  • Check for any stray orm mapping files under Resources/config/doctrine – Cerad Mar 13 '18 at 14:17
  • Checked, and i see no stay orm :( Thanks anyway for the tip dude ! I ll keep searching for an answer, pls lemme know if you have any idea. – Matthieu Mar 14 '18 at 14:29
  • The only other thing that aught my eye is that enterprise is spelt wring. But it looks like you are consistent. I assume you have done the whole cache clearing thing. – Cerad Mar 14 '18 at 15:41
  • Yeah its entrepris cause its a french app, it means company :) And the whole cache clearing is done, several times :( – Matthieu Mar 14 '18 at 16:09
  • What I do when I get stuck like this is to make a fresh project, copy in just the two entities and my query see what happens a bit at a time. Might also try dumping out the sql and running the query manually. – Cerad Mar 14 '18 at 16:14
  • So i tried to run the query manually : php bin/console doctrine:query:sql 'select id from bon where entreprise="test"'; And here is the error i get : An exception occurred while executing 'select id from bon where entreprise= "test"': SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entreprise' in 'where clause' In PDOConnection.php line 106: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entreprise' in 'where clause' In PDOConnection.php line 104: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entreprise' in 'where clause' – Matthieu Mar 15 '18 at 12:36
  • Your actual column name is entreprise_id of course. But the dql processor should take care of that. Sure seems like the orm is not seeing your annotations. Just for grins you could change your JoinColumn to match the docs: https://symfony.com/doc/current/doctrine/associations.html though what you have really should work. – Cerad Mar 15 '18 at 15:25
  • You solved it dude ! THANKS – Matthieu Mar 15 '18 at 16:24
  • Ok, so after doing the change it worked then i executed doctrine:schema:update, and same issue, then i switched again and added _id extension to the name , then re-update, and it works ! I don't even understand anymore :) – Matthieu Mar 15 '18 at 16:29

0 Answers0