{"action":"created","issue":{"url":"https://api.github.com/repos/sdispater/orator/issues/34","labels_url":"https://api.github.com/repos/sdispater/orator/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/sdispater/orator/issues/34/comments","events_url":"https://api.github.com/repos/sdispater/orator/issues/34/events","html_url":"https://github.com/sdispater/orator/issues/34","id":127405658,"number":34,"title":"Eager loading has_many","user":{"login":"camilstaps","id":1202754,"avatar_url":"https://avatars.githubusercontent.com/u/1202754?v=3","gravatar_id":"","url":"https://api.github.com/users/camilstaps","html_url":"https://github.com/camilstaps","followers_url":"https://api.github.com/users/camilstaps/followers","following_url":"https://api.github.com/users/camilstaps/following{/other_user}","gists_url":"https://api.github.com/users/camilstaps/gists{/gist_id}","starred_url":"https://api.github.com/users/camilstaps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camilstaps/subscriptions","organizations_url":"https://api.github.com/users/camilstaps/orgs","repos_url":"https://api.github.com/users/camilstaps/repos","events_url":"https://api.github.com/users/camilstaps/events{/privacy}","received_events_url":"https://api.github.com/users/camilstaps/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-19T09:41:34Z","updated_at":"2016-01-19T18:08:18Z","closed_at":"2016-01-19T18:08:18Z","body":"Is there a way to do eager loading on a has_many relationship?\r\n\r\nWhen I define a relationship, say in class User\r\n\r\n    @has_many\r\n    def articles(self):\r\n        return Article\r\n\r\nAnd query `User.with_('articles')`, N+1 queries are executed. What I would expect is a query like the following:\r\n\r\n    SELECT * FROM user INNER JOIN article ON article.user_id = user.id\r\n\r\nAnd Orator grouping the articles by user and returning User objects that have lists of Article objects. Is something like that currently possible?"},"comment":{"url":"https://api.github.com/repos/sdispater/orator/issues/comments/172936805","html_url":"https://github.com/sdispater/orator/issues/34#issuecomment-172936805","issue_url":"https://api.github.com/repos/sdispater/orator/issues/34","id":172936805,"user":{"login":"camilstaps","id":1202754,"avatar_url":"https://avatars.githubusercontent.com/u/1202754?v=3","gravatar_id":"","url":"https://api.github.com/users/camilstaps","html_url":"https://github.com/camilstaps","followers_url":"https://api.github.com/users/camilstaps/followers","following_url":"https://api.github.com/users/camilstaps/following{/other_user}","gists_url":"https://api.github.com/users/camilstaps/gists{/gist_id}","starred_url":"https://api.github.com/users/camilstaps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camilstaps/subscriptions","organizations_url":"https://api.github.com/users/camilstaps/orgs","repos_url":"https://api.github.com/users/camilstaps/repos","events_url":"https://api.github.com/users/camilstaps/events{/privacy}","received_events_url":"https://api.github.com/users/camilstaps/received_events","type":"User","site_admin":false},"created_at":"2016-01-19T18:08:18Z","updated_at":"2016-01-19T18:08:18Z","body":"Apologies, I was at fault. The model and all was fine, but then I used the relationship as a function instead of a property, i.e.:\r\n\r\n    for user in User.with_('articles').get().all():\r\n        user.articles().get()\r\n\r\ninstead of\r\n\r\n    for user in User.with_('articles').get().all():\r\n        user.articles\r\n\r\nThanks though, and apologies."}}