{"action":"created","issue":{"url":"https://api.github.com/repos/elixirdrops/kerosene/issues/44","repository_url":"https://api.github.com/repos/elixirdrops/kerosene","labels_url":"https://api.github.com/repos/elixirdrops/kerosene/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/elixirdrops/kerosene/issues/44/comments","events_url":"https://api.github.com/repos/elixirdrops/kerosene/issues/44/events","html_url":"https://github.com/elixirdrops/kerosene/issues/44","id":344387387,"node_id":"MDU6SXNzdWUzNDQzODczODc=","number":44,"title":"Preloaded associations with joins","user":{"login":"mbernerslee","id":19970225,"node_id":"MDQ6VXNlcjE5OTcwMjI1","avatar_url":"https://avatars3.githubusercontent.com/u/19970225?v=4","gravatar_id":"","url":"https://api.github.com/users/mbernerslee","html_url":"https://github.com/mbernerslee","followers_url":"https://api.github.com/users/mbernerslee/followers","following_url":"https://api.github.com/users/mbernerslee/following{/other_user}","gists_url":"https://api.github.com/users/mbernerslee/gists{/gist_id}","starred_url":"https://api.github.com/users/mbernerslee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbernerslee/subscriptions","organizations_url":"https://api.github.com/users/mbernerslee/orgs","repos_url":"https://api.github.com/users/mbernerslee/repos","events_url":"https://api.github.com/users/mbernerslee/events{/privacy}","received_events_url":"https://api.github.com/users/mbernerslee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-25T10:33:00Z","updated_at":"2018-12-28T18:52:21Z","closed_at":null,"author_association":"NONE","body":"If I preload accociations using a query that joins the tables, the number of rows returned by the query may be more than the number of rows that are displayed. Kerosene correctly works out the number of rows to display, but then uses this to limit the rows in the query. \r\n\r\nFor example:\r\n```\r\nfrom p in Pet,\r\njoin: vb in VetBooking, on: p.id == vb.pet_id\r\npreload: [vet_booking: vb],\r\nselect: {p, vb}\r\n```\r\n\r\nIf you had 2 pets each with 2 bookings, the query would return 4 rows but only 2 rows should be displayed (one for each pet). Kerosene correctly works out there are 2 rows, but say per_page = 2 it would add `limit 2` to the query, which could just return 1 pet on Page 1... since those 2 rows could be the bookings for 1 pet.\r\n\r\nThis can cause a number of issues:\r\n- some expected results do not appear on any pages at all\r\n- Some pages will show less than the max allowed per_page results, even though there are subsiquent pages"},"comment":{"url":"https://api.github.com/repos/elixirdrops/kerosene/issues/comments/450409008","html_url":"https://github.com/elixirdrops/kerosene/issues/44#issuecomment-450409008","issue_url":"https://api.github.com/repos/elixirdrops/kerosene/issues/44","id":450409008,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDQwOTAwOA==","user":{"login":"joshchernoff","id":961877,"node_id":"MDQ6VXNlcjk2MTg3Nw==","avatar_url":"https://avatars2.githubusercontent.com/u/961877?v=4","gravatar_id":"","url":"https://api.github.com/users/joshchernoff","html_url":"https://github.com/joshchernoff","followers_url":"https://api.github.com/users/joshchernoff/followers","following_url":"https://api.github.com/users/joshchernoff/following{/other_user}","gists_url":"https://api.github.com/users/joshchernoff/gists{/gist_id}","starred_url":"https://api.github.com/users/joshchernoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshchernoff/subscriptions","organizations_url":"https://api.github.com/users/joshchernoff/orgs","repos_url":"https://api.github.com/users/joshchernoff/repos","events_url":"https://api.github.com/users/joshchernoff/events{/privacy}","received_events_url":"https://api.github.com/users/joshchernoff/received_events","type":"User","site_admin":false},"created_at":"2018-12-28T18:52:21Z","updated_at":"2018-12-28T18:52:21Z","author_association":"NONE","body":"This looks related to https://hexdocs.pm/ecto/Ecto.Query.html#preload/3-preload-queries\r\n> Note: keep in mind operations like limit and offset in the preload query will affect the whole result set and not each association. For example, the query below:\r\n\r\n```\r\ncomments_query = from c in Comment, order_by: c.popularity, limit: 5\r\nRepo.all from p in Post, preload: [comments: ^comments_query]\r\n```\r\n> won’t bring the top of comments per post. Rather, it will only bring the 5 top comments across all posts."}}
{"actor":{"display_login":"joshchernoff"}}