I am trying to execute this code :
$em->getConnection()->exec('LOCK TABLES Portfolio t0 WRITE, User u1_ READ);
$portfolio = $this->doctrine->getRepository('Portfolio')->findOneBy(array('user'=>$user->getId(), 'game'=>$game->getId()));
$assets = $this->doctrine->getRepository('Asset')->findBy(array('portfolio' => $portfolio, 'isActive' => 1));
$em->getConnection()->exec('UNLOCK TABLES;');
So when I execute this code I have this Error :
An exception occurred while executing 'SELECT t0.id AS id1 FROM Asset t0' SQLSTATE[HY000]: General error: 1100 Table 't0' was not locked with LOCK TABLES
I must give some explanation before asking the question.
- To do the the lock, we must use doctrine internal aliases (t0, u1_, ...) because doctrine queries findBy, findOneBy finaly use these aliases.
- In MySql, when we lock, we must lock all the tables that are queried within the LOCK and the UNLOCK statements.
- I got the above error because I did not locked the table Asset aliased t0 in my lock statement.
- I can not lock the table Asset with alias t0, because I already have an aliase t0 used for the table Portfolio.
So the question is, can I force doctrine to use a specific internal alias ?