Search code examples
symfonydoctrine-ormfosuserbundlesymfony-2.6

get logged in user with joined data


I'm trying to find a way to get the current logged in user with additional data without running another query, for example lets say each user has one to many relation to messages, so if I run in controller $user = $this->getUser(); $userMessages = $user->getMessages(); I will have to run two queries, I'm looking for a way to force\change the getUser function to pre-load the data with join statement.


Solution

  • Just write your custom query to load the user and add a JOIN

    http://symfony.com/doc/current/cookbook/security/entity_provider.html#using-a-custom-query-to-load-the-user