I have some weird behaviour of doctrine. I've been fighting it since yesterday and I cannot solve the problem.
I have class A that has unidirectional mapping to class B. I have created test for class A that retrives object B
public function setUp()
{
self::bootKernel();
$this->container = self::$kernel->getContainer();
$this->em = $this->container->get('doctrine.orm.entity_manager');
}
public function testStreamingMatchReturnsGuthMatchTable()
{
$a = $this->em->getRepository('AppBundle:A')->find(1);
var_dump($a->getB()); // it returns object B
}
it is working as expected and it returns object B
However when I run the same code but in dev envirorment(from the browser) not CLI it does not return mapping
the code:
public function getAction($id)
{
$a = $this->get('doctrine.orm.entity_manager');
$a = $this->em->getRepository('AppBundle:A')->find(1);
var_dump($a->getB()); // it returns null
}
Relation is marked as:
class A
{
/*
* @ORM\OneToOne(targetEntity="B")
* @ORM\JoinColumn(name="b_id", referencedColumnName="id")
*/
private $b;
}
It isn't original code but it illustrates the problem.
So my question is, how to make relations work in dev environment or what can cause the problem in dev env?
What I've tried already:
- clear cache
- disable cache
- change mapping
- check with DQL // same problem
- try run it with test config on browser
Nothing worked so far and I've got out of ideas.
Edit:
I've noticed that it creates proxy class for test env but it does not create it for dev env.
Edit 2
I've tried to run it on build in Symfony2 server and it works. It does not work on Nginx(vagrant).