{"action":"created","issue":{"url":"https://api.github.com/repos/zendesk/active_record_inherit_assoc/issues/7","labels_url":"https://api.github.com/repos/zendesk/active_record_inherit_assoc/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/zendesk/active_record_inherit_assoc/issues/7/comments","events_url":"https://api.github.com/repos/zendesk/active_record_inherit_assoc/issues/7/events","html_url":"https://github.com/zendesk/active_record_inherit_assoc/pull/7","id":102013991,"number":7,"title":"Fixes inherits with eager-loaded associations returning the wrong records.","user":{"login":"hsume2","id":62437,"avatar_url":"https://avatars.githubusercontent.com/u/62437?v=3","gravatar_id":"","url":"https://api.github.com/users/hsume2","html_url":"https://github.com/hsume2","followers_url":"https://api.github.com/users/hsume2/followers","following_url":"https://api.github.com/users/hsume2/following{/other_user}","gists_url":"https://api.github.com/users/hsume2/gists{/gist_id}","starred_url":"https://api.github.com/users/hsume2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hsume2/subscriptions","organizations_url":"https://api.github.com/users/hsume2/orgs","repos_url":"https://api.github.com/users/hsume2/repos","events_url":"https://api.github.com/users/hsume2/events{/privacy}","received_events_url":"https://api.github.com/users/hsume2/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-19T22:32:14Z","updated_at":"2015-08-21T06:08:31Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/zendesk/active_record_inherit_assoc/pulls/7","html_url":"https://github.com/zendesk/active_record_inherit_assoc/pull/7","diff_url":"https://github.com/zendesk/active_record_inherit_assoc/pull/7.diff","patch_url":"https://github.com/zendesk/active_record_inherit_assoc/pull/7.patch"},"body":"@grosser @pschambacher @osheroff this PR addresses an issue where `:inherit` with `ActiveRecord::QueryMethods#includes` returns the wrong record since the eager-loaded records aren't scoped by the `:inherit` conditions.\r\n\r\nOne approach would be to actually scope the eager-loaded records. However, with multiple owners, we would have to make one query for each owner (essentially re-introducing an N+1).\r\n\r\nThis PR takes the stance that we are okay with loading more records than intended if it means less SQL queries. And we can filter out wrong records in ruby."},"comment":{"url":"https://api.github.com/repos/zendesk/active_record_inherit_assoc/issues/comments/133298497","html_url":"https://github.com/zendesk/active_record_inherit_assoc/pull/7#issuecomment-133298497","issue_url":"https://api.github.com/repos/zendesk/active_record_inherit_assoc/issues/7","id":133298497,"user":{"login":"osheroff","id":260084,"avatar_url":"https://avatars.githubusercontent.com/u/260084?v=3","gravatar_id":"","url":"https://api.github.com/users/osheroff","html_url":"https://github.com/osheroff","followers_url":"https://api.github.com/users/osheroff/followers","following_url":"https://api.github.com/users/osheroff/following{/other_user}","gists_url":"https://api.github.com/users/osheroff/gists{/gist_id}","starred_url":"https://api.github.com/users/osheroff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/osheroff/subscriptions","organizations_url":"https://api.github.com/users/osheroff/orgs","repos_url":"https://api.github.com/users/osheroff/repos","events_url":"https://api.github.com/users/osheroff/events{/privacy}","received_events_url":"https://api.github.com/users/osheroff/received_events","type":"User","site_admin":false},"created_at":"2015-08-21T06:08:31Z","updated_at":"2015-08-21T06:08:31Z","body":"reasonably.  you could also filter down the list further in SQL by adding another IN condition, ie:\r\n\r\n``` \r\n  SELECT * from third where owner_id in (?) and inherited_id in (?)\r\n```\r\n\r\n:+1: "}}