{"action":"created","issue":{"url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/3981","repository_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle","labels_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/3981/labels{/name}","comments_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/3981/comments","events_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/3981/events","html_url":"https://github.com/sonata-project/SonataAdminBundle/issues/3981","id":163377733,"number":3981,"title":"List View: Join by attribute and constant with createQuery()","user":{"login":"chrisp1001","id":14017864,"avatar_url":"https://avatars.githubusercontent.com/u/14017864?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisp1001","html_url":"https://github.com/chrisp1001","followers_url":"https://api.github.com/users/chrisp1001/followers","following_url":"https://api.github.com/users/chrisp1001/following{/other_user}","gists_url":"https://api.github.com/users/chrisp1001/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisp1001/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisp1001/subscriptions","organizations_url":"https://api.github.com/users/chrisp1001/orgs","repos_url":"https://api.github.com/users/chrisp1001/repos","events_url":"https://api.github.com/users/chrisp1001/events{/privacy}","received_events_url":"https://api.github.com/users/chrisp1001/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/labels/unconfirmed","name":"unconfirmed","color":"444444"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-01T11:36:26Z","updated_at":"2016-07-01T12:12:35Z","closed_at":null,"body":"<!--\r\n    Before you open an issue, make sure this one does not already exists.\r\n    Please also read the \"guidelines for contributing\" link above before posting.\r\n-->\r\n\r\n<!--\r\n    If you are reporting a bug, please try to fill in the following.\r\n    Otherwise remove it.\r\n-->\r\n\r\n### Environment\r\n\r\nSymfony 2.7\r\n\r\n#### Symfony packages\r\n\r\n```bash\r\nsymfony/assetic-bundle                   v2.6.1  Integrates Assetic into Symfony2\r\nsymfony/monolog-bundle                   v2.7.1  Symfony MonologBundle\r\nsymfony/swiftmailer-bundle               v2.3.8  Symfony SwiftmailerBundle\r\nsymfony/symfony                          v2.7.1  The Symfony PHP framework\r\n```\r\n\r\n#### Sonata packages\r\n\r\n```bash\r\n$ composer show sonata-project/*\r\nsonata-project/admin-bundle              3.1.0 The missing Symfony Admin Ge...\r\nsonata-project/block-bundle              3.0.0 Symfony SonataBlockBundle\r\nsonata-project/cache                     1.0.7 Cache library\r\nsonata-project/core-bundle               3.0.0 Symfony SonataCoreBundle\r\nsonata-project/doctrine-orm-admin-bundle 3.0.0 Symfony Sonata / Integrate D...\r\nsonata-project/exporter                  1.4.1 Lightweight Exporter library\r\nsonata-project/formatter-bundle          3.0.1 Symfony SonataFormatterBundle\r\n\r\n```\r\n\r\n#### PHP version\r\n\r\n```bash\r\n$ php -v\r\nPHP 5.5.9-1ubuntu4.17 (cli) (built: May 19 2016 19:05:57) \r\nCopyright (c) 1997-2014 The PHP Group\r\nZend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies\r\n    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies\r\n```\r\n\r\n## Subject\r\n\r\nAs it seems that it is not possible to join a table by an attribute as well as a constant, so I needed to find a workaround. I tried to add a join by hand in createQuery function of my admin class like this:\r\n\r\n```php\r\n    protected function configureListFields(ListMapper $listMapper)\r\n    {       \r\n        $listMapper->addIdentifier('offersId', 'integer') // of ProductsOffers Entity\r\n            ->addIdentifier('productsName') // of ProductsDescription Entity\r\n            ->add('_action', 'actions', array(\r\n                    'actions' => array(\r\n                        'edit' => array(),\r\n                    )\r\n            ));\r\n        \r\n    }\r\n    \r\n    public function createQuery($context = 'list')\r\n    {\r\n        $query = parent::createQuery($context);\r\n        \r\n        $query->addSelect('p')->from('AppBundle:ProductsDescription', 'p')\r\n                ->andWhere($query->getRootAlias().'.productsId = p.productsId') // join by attribute\r\n                ->andWhere('p.languageId = 2'); // join by constant\r\n        \r\n        return $query;\r\n    }\r\n```\r\n\r\nNote: The ProductsDescription Entity has a compount primary key of productsId and languageId:\r\n\r\n```php\r\n    class ProductsOffers\r\n    {\r\n    /**\r\n     * @var integer\r\n     *\r\n     * @ORM\\Column(name=\"products_id\", type=\"integer\", nullable=true)\r\n     */\r\n    private $productsId;\r\n\r\n      .....\r\n    }\r\n\r\n\r\n    class ProductsDescription\r\n    {\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"products_name\", type=\"string\", length=255, nullable=false)\r\n     */\r\n    private $productsName;\r\n\r\n    /**\r\n     * @var integer\r\n     *\r\n     * @ORM\\Column(name=\"products_id\", type=\"integer\")\r\n     * @ORM\\Id\r\n     * @ORM\\GeneratedValue(strategy=\"NONE\")\r\n     */\r\n    private $productsId;\r\n\r\n    /**\r\n     * @var integer\r\n     *\r\n     * @ORM\\Column(name=\"language_id\", type=\"integer\")\r\n     * @ORM\\Id\r\n     * @ORM\\GeneratedValue(strategy=\"NONE\")\r\n     */\r\n    private $languageId;\r\n\r\n    ......\r\n    }\r\n```\r\n\r\n<!--\r\n    Give here as many details as possible.\r\n    Next sections are for ERRORS only.\r\n-->\r\n\r\n## Steps to reproduce\r\n\r\n## Expected results\r\n\r\nI would expect that there would be shown a productsName in every dataset in the list view.\r\n\r\n## Actual results\r\n\r\nHowever every productsDescription as well as every productsOffers entity gets an own line in the list view. Furthermore every productsName is only shown once. If there are more productsOffers.productsId that reference one and the same entity (one to many) in productsOffers, the productsName is only shown for the first entity of productsDescription which results in:\r\n\r\n![screenshot - 01 07 2016 - 13 31 19](https://cloud.githubusercontent.com/assets/14017864/16520431/54dbfd42-3f90-11e6-965a-3277b49324cb.png)\r\n\r\nFor offersId 173, 172, 171 should be shown a productsName as well but is not as one of the entities above them already showed the productsName of the entity 173, 172, 171 is linked to as well.\r\n\r\nFurthermore one result dataset should be shown in one line not two.\r\n\r\n\r\n<!--\r\n    If it's an error message or piece of code, use code block tags,\r\n    and make sure you provide the whole stack trace(s),\r\n    not just the first error message you can see.\r\n    More details here: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/CONTRIBUTING.md#issues\r\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/comments/229931246","html_url":"https://github.com/sonata-project/SonataAdminBundle/issues/3981#issuecomment-229931246","issue_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/3981","id":229931246,"user":{"login":"Soullivaneuh","id":1698357,"avatar_url":"https://avatars.githubusercontent.com/u/1698357?v=3","gravatar_id":"","url":"https://api.github.com/users/Soullivaneuh","html_url":"https://github.com/Soullivaneuh","followers_url":"https://api.github.com/users/Soullivaneuh/followers","following_url":"https://api.github.com/users/Soullivaneuh/following{/other_user}","gists_url":"https://api.github.com/users/Soullivaneuh/gists{/gist_id}","starred_url":"https://api.github.com/users/Soullivaneuh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Soullivaneuh/subscriptions","organizations_url":"https://api.github.com/users/Soullivaneuh/orgs","repos_url":"https://api.github.com/users/Soullivaneuh/repos","events_url":"https://api.github.com/users/Soullivaneuh/events{/privacy}","received_events_url":"https://api.github.com/users/Soullivaneuh/received_events","type":"User","site_admin":false},"created_at":"2016-07-01T12:12:35Z","updated_at":"2016-07-01T12:12:35Z","body":"Your sonata dependencies are not up to date. For example, admin-bundle last version is 3.3.2, not 3.1.0.\r\n\r\nPlease update and tel us if the issue is still here."}}
{"actor":{"display_login":"Soullivaneuh"}}