{"action":"created","issue":{"url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/1265","repository_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle","labels_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/1265/labels{/name}","comments_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/1265/comments","events_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/1265/events","html_url":"https://github.com/javiereguiluz/EasyAdminBundle/issues/1265","id":169751425,"number":1265,"title":"[Feature Request] Defining the repository method to fetch the entity","user":{"login":"hhamon","id":235550,"avatar_url":"https://avatars.githubusercontent.com/u/235550?v=3","gravatar_id":"","url":"https://api.github.com/users/hhamon","html_url":"https://github.com/hhamon","followers_url":"https://api.github.com/users/hhamon/followers","following_url":"https://api.github.com/users/hhamon/following{/other_user}","gists_url":"https://api.github.com/users/hhamon/gists{/gist_id}","starred_url":"https://api.github.com/users/hhamon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hhamon/subscriptions","organizations_url":"https://api.github.com/users/hhamon/orgs","repos_url":"https://api.github.com/users/hhamon/repos","events_url":"https://api.github.com/users/hhamon/events{/privacy}","received_events_url":"https://api.github.com/users/hhamon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2016-08-06T15:26:13Z","updated_at":"2016-08-08T14:11:44Z","closed_at":null,"body":"When executing the `edit`, `show` and `delete` actions, the entity is fetched using the `find()` method of the repository class. For most of the entities it's fine to just fetch it with the generic `find()` method. However, I have some complex entities that are in relation with other entities. In this particular situation, the `edit`  and `show` views perform lots of SQL queries to lazy load these related entities.\r\n\r\nImagine a `Product` entity that has the following relationships:\r\n\r\n- A many-to-many relationship with a `ProductCategory` entity\r\n- A one-to-many relationship with a `Price` entity\r\n- A many-to-many relationshop with a `Tag` entity\r\n- A one-to-many relationship with a  `ProductAttribute` entity (which also has nested relationships).\r\n- ...\r\n\r\nWhen I'm on the `edit` or `show` views of my `Product` entity and want to manage the related entities, it leads to make Doctrine execute many SQL queries to lazy load the relationships.\r\n\r\nCould we update the `RequestPostInitializeListener` listener to make it support the choice of a configured repository method to invoke when fetching the entity in a more optimized manner?\r\n\r\nIt would be interesting to do something like the following:\r\n\r\n```\r\neasy_admin:\r\n    entities:\r\n        Product:\r\n            edit:\r\n                repository_method: findComplete\r\n            show:\r\n                repository_method: findOptimized\r\n        # ...\r\n```\r\n\r\nWhat do you think?\r\n\r\n@javiereguiluz @ogizanagi \r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/comments/238249947","html_url":"https://github.com/javiereguiluz/EasyAdminBundle/issues/1265#issuecomment-238249947","issue_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/1265","id":238249947,"user":{"login":"yceruto","id":2028198,"avatar_url":"https://avatars.githubusercontent.com/u/2028198?v=3","gravatar_id":"","url":"https://api.github.com/users/yceruto","html_url":"https://github.com/yceruto","followers_url":"https://api.github.com/users/yceruto/followers","following_url":"https://api.github.com/users/yceruto/following{/other_user}","gists_url":"https://api.github.com/users/yceruto/gists{/gist_id}","starred_url":"https://api.github.com/users/yceruto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yceruto/subscriptions","organizations_url":"https://api.github.com/users/yceruto/orgs","repos_url":"https://api.github.com/users/yceruto/repos","events_url":"https://api.github.com/users/yceruto/events{/privacy}","received_events_url":"https://api.github.com/users/yceruto/received_events","type":"User","site_admin":false},"created_at":"2016-08-08T14:11:44Z","updated_at":"2016-08-08T14:11:44Z","body":"Then, the data source is responsibility from data providers (ORM, ODM, ...) and the result process should be responsibility of several extensions associated to data provider:\r\n\r\nFor example, if we wanted to perform the search action (ORM), this would pass by three extensions:\r\n1- build the basic query to list the results of the given resource class (for list, search, autocomplete actions).\r\n2- add `where` statements to query given the term/id (for search, autocomplete, edit, show, delete actions).\r\n3- paginate the result (for list, search, autocomplete actions).\r\n\r\n(Now, if we wanted to display the list only, execute extensions 1 and 3)\r\n\r\nI see this as one extension that subscribe to some actions and they are executed in a logical order. In this way, we could add an intermediate extension without making the whole process.\r\n\r\n LGTM.\r\n\r\n> The only thing that is a shame is that it will require a lot of duplication from the api-platform/api-core repository. I don't know if it'll be pertinent to extract those abstraction layers & bridges in some new packages nor if it's possible (the ORM implementation relies on api-platform custom metadata).\r\n\r\nI think that @javiereguiluz is the most appropriate to give this answer and approve this big feature too :)"}}
{"actor":{"display_login":"yceruto"}}