{"action":"created","issue":{"url":"https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/issues/584","repository_url":"https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle","labels_url":"https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/issues/584/labels{/name}","comments_url":"https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/issues/584/comments","events_url":"https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/issues/584/events","html_url":"https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/584","id":159175976,"number":584,"title":"Admin creates too many queries","user":{"login":"clytemnestra","id":7060048,"avatar_url":"https://avatars.githubusercontent.com/u/7060048?v=3","gravatar_id":"","url":"https://api.github.com/users/clytemnestra","html_url":"https://github.com/clytemnestra","followers_url":"https://api.github.com/users/clytemnestra/followers","following_url":"https://api.github.com/users/clytemnestra/following{/other_user}","gists_url":"https://api.github.com/users/clytemnestra/gists{/gist_id}","starred_url":"https://api.github.com/users/clytemnestra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clytemnestra/subscriptions","organizations_url":"https://api.github.com/users/clytemnestra/orgs","repos_url":"https://api.github.com/users/clytemnestra/repos","events_url":"https://api.github.com/users/clytemnestra/events{/privacy}","received_events_url":"https://api.github.com/users/clytemnestra/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":32,"created_at":"2016-06-08T14:21:10Z","updated_at":"2016-06-13T12:32:59Z","closed_at":null,"body":"Following https://github.com/sonata-project/SonataAdminBundle/issues/3924\r\n\r\n\r\n<!--\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| Question       | Answer\r\n|----------------|-------------------------------\r\n| Bundle version | composer show sonata-project/*\r\n||sonata-project/admin-bundle              3.x-dev 62c313c    The missing Symfony Admin Generator\r\n||sonata-project/block-bundle              3.x-dev ee778ac    Symfony SonataBlockBundle\r\n||sonata-project/cache                     1.0.7              Cache library\r\n||sonata-project/classification-bundle     3.x-dev aa61d55    Symfony SonataClassificationBundle\r\n||sonata-project/core-bundle               3.x-dev d2f84a6    Symfony SonataCoreBundle\r\n||sonata-project/datagrid-bundle           dev-master 311afa1 Symfony SonataDatagridBundle\r\n||sonata-project/doctrine-extensions       1.0.2              Doctrine2 behavioral extensions\r\n||sonata-project/doctrine-orm-admin-bundle 3.x-dev 3c85820    Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle\r\n||sonata-project/easy-extends-bundle       2.1.10             Symfony SonataEasyExtendsBundle\r\n||sonata-project/exporter                  1.4.1              Lightweight Exporter library\r\n||sonata-project/intl-bundle               2.2.4              Symfony SonataIntlBundle\r\n||sonata-project/media-bundle              3.x-dev ec413fa    Symfony SonataMediaBundle\r\n||sonata-project/notification-bundle       3.0.0              Symfony SonataNotificationBundle\r\n|Symfony version| composer show symfony/*\r\n||symfony/assetic-bundle     v2.8.0  Integrates Assetic into Symfony2\r\n||symfony/monolog-bundle     2.11.1  Symfony MonologBundle\r\n||symfony/polyfill-apcu      v1.2.0  Symfony polyfill backporting apcu_* functions to lower PHP versions\r\n||symfony/polyfill-intl-icu  v1.2.0  Symfony polyfill for intl's ICU-related data and classes\r\n||symfony/polyfill-mbstring  v1.2.0  Symfony polyfill for the Mbstring extension\r\n||symfony/polyfill-php54     v1.2.0  Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions\r\n||symfony/polyfill-php55     v1.2.0  Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions\r\n||symfony/polyfill-php56     v1.2.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions\r\n||symfony/polyfill-php70     v1.2.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions\r\n||symfony/polyfill-util      v1.2.0  Symfony utilities for portability of PHP codes\r\n||symfony/security-acl       v3.0.0  Symfony Security Component - ACL (Access Control List)\r\n||symfony/swiftmailer-bundle v2.3.11 Symfony SwiftmailerBundle\r\n||symfony/symfony            v2.8.6  The Symfony PHP framework\r\n| php version    | php --version\r\n||PHP 5.6.20 (cli) (built: Mar 31 2016 14:56:44)\r\n||Copyright (c) 1997-2016 The PHP Group\r\n||Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies\r\n\r\n# Error message\r\n\r\nThe SF debug bar shows too many queries on all my admin classes. My admin classes have nothing custom. I played a bit with my entities and found out that if I delete the mappedBy fields from my User class, it doesn't do those queries anymore, but then the entity is not valid anymore, since it needs mappedBy for every inversedBy field.\r\n\r\n\r\n# Steps to reproduce\r\n\r\n\r\nThe admin's entity\r\n\r\n```php\r\n/**\r\n * @ORM\\Table()\r\n * @ORM\\Entity\r\n */\r\nclass BannedUsers\r\n{\r\n    /**\r\n     * @var integer\r\n     *\r\n     * @ORM\\Column(name=\"id\", type=\"integer\")\r\n     * @ORM\\Id\r\n     * @ORM\\GeneratedValue(strategy=\"AUTO\")\r\n     */\r\n    private $id;\r\n\r\n    /**\r\n     * @ORM\\ManyToOne(targetEntity=\"User\")\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\",onDelete=\"CASCADE\")\r\n     */\r\n    private $user;\r\n\r\n    /**\r\n     * @ORM\\ManyToOne(targetEntity=\"User\")\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\",onDelete=\"CASCADE\")\r\n     */\r\n    private $censor;\r\n\r\n    /**\r\n     * @ORM\\Column(type=\"string\",nullable=true,length=2000)\r\n     */\r\n    private $reason;\r\n\r\n\r\n    /**\r\n     * @ORM\\Column(type=\"boolean\")\r\n     */\r\n    private $isBanActive=true;\r\n\r\n    /**\r\n     * @ORM\\Column(type=\"datetime\")\r\n     * @Timestampable(on=\"create\")\r\n     */\r\n    private $bannedAt;\r\n```\r\n\r\nThis is my user class, pretty big but maybe it helps:\r\n\r\n```php\r\n/**\r\n * @ORM\\Entity(repositoryClass=\"UserRepository\")\r\n * @ORM\\Table(name=\"fos_user\")\r\n */\r\nclass User extends BaseUser\r\n{\r\n    const DEFAULT_PATIENT_CREDIT = 300;\r\n\r\n    /**\r\n     * @ORM\\Id\r\n     * @ORM\\Column(type=\"integer\")\r\n     * @ORM\\GeneratedValue(strategy=\"AUTO\")\r\n     */\r\n    protected $id;\r\n\r\n    /**\r\n     * @ORM\\ManyToMany(targetEntity=\"MedAppBundle\\Entity\\Group\",inversedBy=\"users\")\r\n     * @ORM\\JoinTable(name=\"fos_user_user_group\",\r\n     *      joinColumns={@ORM\\JoinColumn(name=\"user_id\", referencedColumnName=\"id\",onDelete=\"CASCADE\")},\r\n     *      inverseJoinColumns={@ORM\\JoinColumn(name=\"group_id\", referencedColumnName=\"id\")}\r\n     * )\r\n     */\r\n    protected $groups;\r\n\r\n\r\n    /**\r\n     * @var string\r\n     * @Assert\\NotBlank(message=\"user.firstname.blank\",groups={\"Profile\"})\r\n     * @ORM\\Column(name=\"firstname\", type=\"string\",nullable=true)\r\n     */\r\n    protected $firstname;\r\n\r\n    /**\r\n     * @var string\r\n     * @Assert\\NotBlank(message=\"user.lastname.blank\",groups={\"Profile\"})\r\n     * @ORM\\Column(name=\"lastname\", type=\"string\",nullable=true)\r\n     */\r\n    protected $lastname;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"phoneno\", type=\"string\",nullable=true)\r\n     */\r\n    protected $phoneno;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"registration_ip\", type=\"string\",nullable=true)\r\n     */\r\n    protected $registrationIp;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"effects\", type=\"boolean\")\r\n     */\r\n    protected $effects = true;\r\n    /**\r\n     *\r\n     * @ORM\\Column(name=\"public_email\", type=\"boolean\")\r\n     */\r\n    protected $public_email = true;\r\n    /**\r\n     * @Assert\\Valid\r\n     * @ORM\\OneToOne(targetEntity=\"MedAppBundle\\Entity\\MedicSettings\",mappedBy=\"medic\", cascade={\"persist\"})\r\n     * @Assert\\Valid()\r\n     */\r\n    protected $medicinfo;\r\n    /**\r\n     * @ORM\\OneToMany(targetEntity=\"MedAppBundle\\Entity\\MedicComm\",mappedBy=\"medic\")\r\n     */\r\n    protected $mediccomm;\r\n\r\n    /**\r\n     * @ORM\\OneToOne(targetEntity=\"PrivateMessageBundle\\Entity\\MessageSettings\",mappedBy=\"user\",cascade={\"persist\"})\r\n     */\r\n    protected $messageSettings;\r\n\r\n\r\n    /**\r\n     * @ORM\\OneToOne(targetEntity=\"SupportMessageBundle\\Entity\\TicketSettings\",mappedBy=\"user\",cascade={\"persist\"})\r\n     */\r\n    protected $ticketSettings;\r\n\r\n    /**\r\n     * @ORM\\OneToOne(targetEntity=\"Application\\Sonata\\MediaBundle\\Entity\\Media\",cascade={\"persist\"})\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\",onDelete=\"SET NULL\")\r\n     */\r\n    protected $profilepic;\r\n\r\n    /**\r\n     * @var Media\r\n     *\r\n     * @ORM\\OneToMany(targetEntity=\"Application\\Sonata\\MediaBundle\\Entity\\Media\", mappedBy=\"user\")\r\n     * @ORM\\JoinColumn(name=\"images\", referencedColumnName=\"id\",nullable=true)\r\n     */\r\n    private $images;\r\n\r\n    /**\r\n     * @var Media\r\n     *\r\n     * @ORM\\OneToMany(targetEntity=\"Application\\Sonata\\MediaBundle\\Entity\\Gallery\", mappedBy=\"user\")\r\n     * @ORM\\JoinColumn(name=\"galleries\", referencedColumnName=\"id\",nullable=true)\r\n     */\r\n    private $galleries;\r\n\r\n\r\n\r\n    /**\r\n     * @var float\r\n     *\r\n     * @ORM\\Column(name=\"credit\", type=\"float\")\r\n     */\r\n    protected $credit = 0;\r\n\r\n    /**\r\n     *\r\n     * @ORM\\ManyToOne(targetEntity=\"MedAppBundle\\Entity\\User\")\r\n     * @ORM\\JoinColumn(name=\"referredBy\", referencedColumnName=\"id\",nullable=true,onDelete=\"SET NULL\")\r\n     */\r\n    protected $referredBy;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"locationData\", type=\"string\",nullable=true)\r\n     */\r\n    protected $locationData;\r\n\r\n    /**\r\n     * @ORM\\OneToMany(targetEntity=\"MedAppBundle\\Entity\\Stream\",mappedBy=\"streamer\")\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\")\r\n     */\r\n    private $streams;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"savedFilters\", type=\"string\",nullable=true)\r\n     */\r\n    protected $savedFilters;\r\n\r\n\r\n    /**\r\n     *\r\n     * @ORM\\Column(name=\"registration_date\", type=\"datetime\",nullable=true)\r\n     */\r\n    protected $registrationDate;\r\n\r\n    /**\r\n     * @ORM\\OneToMany(targetEntity=\"MedAppBundle\\Entity\\FavoriteUsers\",mappedBy=\"user\")\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\")\r\n     */\r\n    private $favUsers;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"chosen_theme\", type=\"string\",nullable=true)\r\n     */\r\n    protected $chosenTheme;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"site_lang\", type=\"string\",nullable=true)\r\n     */\r\n    protected $siteLang;\r\n\r\n    /**\r\n     * @var integer\r\n     *\r\n     * @ORM\\Column(name=\"total_time_live\", type=\"integer\", nullable=true)\r\n     *\r\n     */\r\n    protected $totalTimeLive;\r\n\r\n    /**\r\n     *\r\n     * @ORM\\ManyToOne(targetEntity=\"FirmBundle\\Entity\\Firm\",inversedBy=\"firmAdmins\", cascade={\"persist\"})\r\n     */\r\n    protected $adminOfFirm;\r\n\r\n    /**\r\n     * @ORM\\OneToMany(targetEntity=\"MedAppBundle\\Entity\\EmailList\",mappedBy=\"user\")\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\")\r\n     */\r\n    private $emailList;\r\n\r\n    /**\r\n     * @ORM\\OneToOne(targetEntity=\"MedAppBundle\\Entity\\Newsletter\",mappedBy=\"user\")\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\")\r\n     */\r\n    private $newsletter;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"folderName\", type=\"string\", nullable=true)\r\n     */\r\n    public $folderName;\r\n\r\n    /**\r\n     *\r\n     * @ORM\\Column(name=\"bonus_received\", type=\"boolean\")\r\n     */\r\n    protected $bonusReceived = false;\r\n\r\n    /**\r\n     *\r\n     * @ORM\\Column(name=\"purchase_bonus_eligibility\", type=\"boolean\", options={\"default\" = true }, nullable=true )\r\n     */\r\n    protected $purchaseBonusEligibility;\r\n\r\n    /**\r\n     * @ORM\\OneToMany(targetEntity=\"MedAppBundle\\Entity\\PendingProfileImage\",mappedBy=\"user\")\r\n     */\r\n    protected $pendingProfileImages;\r\n\r\n    /**\r\n     * @ORM\\Column(name=\"is_validated_phone_no\", type=\"boolean\", nullable=true)\r\n     */\r\n    private $isValidatedPhoneNo;\r\n\r\n    /**\r\n     * @ORM\\Column(name=\"mobile_validation_pin\", type=\"string\", nullable=true)\r\n     */\r\n    private $mobileValidationPin;\r\n\r\n    /**\r\n     * @ORM\\Column(name=\"username_token\", type=\"string\", nullable=true, options={\"default\" = true })\r\n     */\r\n    private $usernameToken;\r\n\r\n\r\n\r\n\r\n    /**\r\n     * @ORM\\OneToOne(targetEntity=\"MedAppBundle\\Entity\\AccountDocument\", mappedBy=\"user\")\r\n     */\r\n    private $accountDocument;\r\n\r\n\r\n    /**\r\n     * @ORM\\OneToMany(targetEntity=\"MedAppBundle\\Entity\\AccountDocument\", mappedBy=\"takenByAdmin\")\r\n     * @ORM\\JoinColumn(referencedColumnName=\"id\",onDelete=\"CASCADE\")\r\n     */\r\n    private $takenPending;\r\n```\r\n\r\n\r\n\r\n\r\n# Expected results\r\nIf I delete all the mappedBy fields, the same page on my admin shows less queries, as I want it to be, but invalid entity:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/7060048/15884903/147cb570-2d5c-11e6-9cb7-93fe621d242e.png)\r\n\r\nHere's the queries table\r\nhttps://jsfiddle.net/nmxz4j7y/\r\n\r\n# Actual results\r\n\r\n\r\n\r\nHere's one of my admin classes's example:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/7060048/15884782/69bd14cc-2d5b-11e6-8307-09824e97cc48.png)\r\n\r\nHere's the query table:\r\nhttps://jsfiddle.net/nmxz4j7y/1/"},"comment":{"url":"https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/issues/comments/225567866","html_url":"https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/584#issuecomment-225567866","issue_url":"https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/issues/584","id":225567866,"user":{"login":"greg0ire","id":657779,"avatar_url":"https://avatars.githubusercontent.com/u/657779?v=3","gravatar_id":"","url":"https://api.github.com/users/greg0ire","html_url":"https://github.com/greg0ire","followers_url":"https://api.github.com/users/greg0ire/followers","following_url":"https://api.github.com/users/greg0ire/following{/other_user}","gists_url":"https://api.github.com/users/greg0ire/gists{/gist_id}","starred_url":"https://api.github.com/users/greg0ire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greg0ire/subscriptions","organizations_url":"https://api.github.com/users/greg0ire/orgs","repos_url":"https://api.github.com/users/greg0ire/repos","events_url":"https://api.github.com/users/greg0ire/events{/privacy}","received_events_url":"https://api.github.com/users/greg0ire/received_events","type":"User","site_admin":false},"created_at":"2016-06-13T12:32:59Z","updated_at":"2016-06-13T12:32:59Z","body":"Ok great… I'm out of ideas, sorry :("}}
{"actor":{"display_login":"greg0ire"}}