{"action":"created","issue":{"url":"https://api.github.com/repos/Atlantic18/DoctrineExtensions/issues/1392","labels_url":"https://api.github.com/repos/Atlantic18/DoctrineExtensions/issues/1392/labels{/name}","comments_url":"https://api.github.com/repos/Atlantic18/DoctrineExtensions/issues/1392/comments","events_url":"https://api.github.com/repos/Atlantic18/DoctrineExtensions/issues/1392/events","html_url":"https://github.com/Atlantic18/DoctrineExtensions/issues/1392","id":101859233,"number":1392,"title":"[Translatable] Unexpected but correct behavior on creating and flushing new translatable entity object from Symfony2 console command","user":{"login":"dvapelnik","id":1562244,"avatar_url":"https://avatars.githubusercontent.com/u/1562244?v=3","gravatar_id":"","url":"https://api.github.com/users/dvapelnik","html_url":"https://github.com/dvapelnik","followers_url":"https://api.github.com/users/dvapelnik/followers","following_url":"https://api.github.com/users/dvapelnik/following{/other_user}","gists_url":"https://api.github.com/users/dvapelnik/gists{/gist_id}","starred_url":"https://api.github.com/users/dvapelnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvapelnik/subscriptions","organizations_url":"https://api.github.com/users/dvapelnik/orgs","repos_url":"https://api.github.com/users/dvapelnik/repos","events_url":"https://api.github.com/users/dvapelnik/events{/privacy}","received_events_url":"https://api.github.com/users/dvapelnik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-19T10:36:59Z","updated_at":"2015-08-19T12:44:19Z","closed_at":null,"body":"I'm using [nesting translatable extension](https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md#nesting-translatable-and-sluggable-extensions) from repository documentation on Symfony2 project with [configuration manual for Symfony2](https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/symfony2.md) from repository documentation too. I'm using `uk` as default application locale and `ru` as locale fallback. But Doctrine2 always creates addition record on `ext_translations` table with `en_US` locale and content with value such as value on default locale.\r\n\r\n```php\r\n// AppBundle\\Command\\SomeCommand::execute($input, $output)\r\n$category = new Category();\r\n$category->setId(1);\r\n$category->setTitle('TITLE_DEFAULT');\r\n\r\n$em = $this->getContainer()->get('doctrine')->getManager();\r\n$repo = $em->getRepository('Gedmo:Translation');\r\n\r\n$repo->translate($category, 'title', 'uk', 'TITLE_UK');\r\n$repo->translate($category, 'title', 'ru', 'TITLE_RU');\r\n\r\n$em->persist($category);\r\n$em->flush();\r\n```\r\n```\r\nmysql> select * from categories;\r\n+----+-----------+-----+-----+------+-----+----------+\r\n| id | parent_id | lft | rgt | root | lvl | title    |\r\n+----+-----------+-----+-----+------+-----+----------+\r\n|  1 |      NULL |   1 |   2 |    1 |   0 | TITLE_UK |\r\n+----+-----------+-----+-----+------+-----+----------+\r\n1 row in set (0.00 sec)\r\n```\r\n```\r\nmysql> select * from ext_translations;\r\n+----+--------+---------------------------+-------+-------------+---------------+\r\n| id | locale | object_class              | field | foreign_key | content       |\r\n+----+--------+---------------------------+-------+-------------+---------------+\r\n|  1 | en_US  | AppBundle\\Entity\\Category | title | 1           | TITLE_DEFAULT |\r\n|  2 | ru     | AppBundle\\Entity\\Category | title | 1           | TITLE_RU      |\r\n+----+--------+---------------------------+-------+-------------+---------------+\r\n2 rows in set (0.00 sec)\r\n```\r\nThe reason is DoctrineExtensionListener::onLateKernelRequest is never called on Symfony2 console command.\r\n\r\nMy local workaround is setting up translatable locale for `gedmo.listener.translatable` manually such as default application locale before using Translatable DoctrineExtension\r\n```php\r\n// AppBundle\\Command\\SomeCommand::execute($input, $output)\r\n$container = $this->getContainer();\r\n$container->get('gedmo.listener.translatable')\r\n    ->setTranslatableLocale($container->getParameter('locale'));\r\n```\r\n```\r\nmysql> select * from categories;      \r\n+----+-----------+-----+-----+------+-----+----------+\r\n| id | parent_id | lft | rgt | root | lvl | title    |\r\n+----+-----------+-----+-----+------+-----+----------+\r\n|  1 |      NULL |   1 |   2 |    1 |   0 | TITLE_UK |\r\n+----+-----------+-----+-----+------+-----+----------+\r\n1 row in set (0.00 sec)\r\n```\r\n```\r\nmysql> select * from ext_translations;\r\n+----+--------+---------------------------+-------+-------------+----------+\r\n| id | locale | object_class              | field | foreign_key | content  |\r\n+----+--------+---------------------------+-------+-------------+----------+\r\n|  1 | ru     | AppBundle\\Entity\\Category | title | 1           | TITLE_RU |\r\n+----+--------+---------------------------+-------+-------------+----------+\r\n1 row in set (0.00 sec)\r\n```\r\nI think that this behavior should be added into Symfony2 [configuration](https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/symfony2.md) with DoctrineExtensions as caution."},"comment":{"url":"https://api.github.com/repos/Atlantic18/DoctrineExtensions/issues/comments/132577927","html_url":"https://github.com/Atlantic18/DoctrineExtensions/issues/1392#issuecomment-132577927","issue_url":"https://api.github.com/repos/Atlantic18/DoctrineExtensions/issues/1392","id":132577927,"user":{"login":"l3pp4rd","id":132389,"avatar_url":"https://avatars.githubusercontent.com/u/132389?v=3","gravatar_id":"","url":"https://api.github.com/users/l3pp4rd","html_url":"https://github.com/l3pp4rd","followers_url":"https://api.github.com/users/l3pp4rd/followers","following_url":"https://api.github.com/users/l3pp4rd/following{/other_user}","gists_url":"https://api.github.com/users/l3pp4rd/gists{/gist_id}","starred_url":"https://api.github.com/users/l3pp4rd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l3pp4rd/subscriptions","organizations_url":"https://api.github.com/users/l3pp4rd/orgs","repos_url":"https://api.github.com/users/l3pp4rd/repos","events_url":"https://api.github.com/users/l3pp4rd/events{/privacy}","received_events_url":"https://api.github.com/users/l3pp4rd/received_events","type":"User","site_admin":false},"created_at":"2015-08-19T12:44:19Z","updated_at":"2015-08-19T12:44:19Z","body":"great, thanks, that is indeed a needed update ;)"}}