{"action":"reopened","issue":{"url":"https://api.github.com/repos/elixir-ecto/ecto/issues/2664","repository_url":"https://api.github.com/repos/elixir-ecto/ecto","labels_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/2664/labels{/name}","comments_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/2664/comments","events_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/2664/events","html_url":"https://github.com/elixir-ecto/ecto/issues/2664","id":352511509,"node_id":"MDU6SXNzdWUzNTI1MTE1MDk=","number":2664,"title":"Preload not loading all data?","user":{"login":"gmile","id":207112,"node_id":"MDQ6VXNlcjIwNzExMg==","avatar_url":"https://avatars2.githubusercontent.com/u/207112?v=4","gravatar_id":"","url":"https://api.github.com/users/gmile","html_url":"https://github.com/gmile","followers_url":"https://api.github.com/users/gmile/followers","following_url":"https://api.github.com/users/gmile/following{/other_user}","gists_url":"https://api.github.com/users/gmile/gists{/gist_id}","starred_url":"https://api.github.com/users/gmile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmile/subscriptions","organizations_url":"https://api.github.com/users/gmile/orgs","repos_url":"https://api.github.com/users/gmile/repos","events_url":"https://api.github.com/users/gmile/events{/privacy}","received_events_url":"https://api.github.com/users/gmile/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-08-21T12:13:49Z","updated_at":"2018-08-21T13:04:14Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I'm facing Ecto behaviour I'm having hard time explaining to myself. Consider this example, which is also published on github as a standalone mix app – [`ecto_redundancy_issue`](https://github.com/gmile/ecto_redundancy_issue).\r\n\r\n<details>\r\n<summary>Schemas (hidden for brevity)</summary>\r\n\r\n```elixir\r\ndefmodule Author do\r\n  use Ecto.Schema\r\n\r\n  schema \"authors\" do\r\n    field :full_name, :string\r\n    field :email, :string\r\n  end\r\nend\r\n\r\ndefmodule Comment do\r\n  use Ecto.Schema\r\n\r\n  schema \"comments\" do\r\n    field :subject, :string\r\n    field :content, :string\r\n    field :post_id, :integer\r\n\r\n    belongs_to :author, Author\r\n  end\r\nend\r\n\r\ndefmodule Post do\r\n  use Ecto.Schema\r\n\r\n  schema \"posts\" do\r\n    field :title, :string\r\n    field :body, :string\r\n\r\n    has_many :comments, Comment\r\n    has_many :commenters, through: [:comments, :author]\r\n  end\r\nend\r\n```\r\n</details>\r\n\r\n\r\nData:\r\n```elixir\r\nRedundancyRepo.insert_all(\"posts\", [\r\n  %{id: 1, title: \"My title\", body: \"My body\"}\r\n])\r\n\r\nRedundancyRepo.insert_all(\"authors\", [\r\n  %{id: 1, full_name: \"Full name 1\", email: \"client1@server.com\"},\r\n  %{id: 2, full_name: \"Full name 2\", email: \"client2@server.com\"},\r\n  %{id: 3, full_name: \"Full name 3\", email: \"client3@server.com\"}\r\n])\r\n\r\nRedundancyRepo.insert_all(\"comments\", [\r\n  %{id: 1, post_id: 1, author_id: 1, subject: \"Subject 1\", content: \"Big content 1\"},\r\n  %{id: 2, post_id: 1, author_id: 2, subject: \"Subject 2\", content: \"Big content 2\"},\r\n  %{id: 3, post_id: 1, author_id: 3, subject: \"Subject 3\", content: \"Big content 3\"},\r\n  %{id: 4, post_id: 1, author_id: 1, subject: \"Subject 4\", content: \"Big content 4\"},\r\n  %{id: 5, post_id: 1, author_id: 2, subject: \"Subject 5\", content: \"Big content 5\"},\r\n  %{id: 6, post_id: 1, author_id: 3, subject: \"Subject 6\", content: \"Big content 6\"}\r\n])\r\n```\r\n\r\nTest code:\r\n\r\n```elixir\r\ncommenter_emails_query = from a in Author, select: struct(a, [:email])\r\nposts_query = from p in Post, preload: [commenters: ^commenter_emails_query]\r\n\r\n[post] = RedundancyRepo.all(posts_query)\r\npost.commenters == Enum.map(post.comments, & &1.author) |> Enum.uniq |> Enum.sort # => false\r\n```\r\n\r\nI expect the final statement to be `true`. What am I missing?\r\n\r\n### Environment\r\n\r\n* Elixir version: Elixir 1.7.2 (compiled with Erlang/OTP 21)\r\n* Database and version: PostgreSQL 10.5\r\n* Ecto version (mix deps): master branch, specifically 63d075d66201819e37d6774f155a487ace583855\r\n* Database adapter and version (mix deps): 0.13.5\r\n* Operating system: macOS\r\n\r\n### Current behavior\r\n\r\nPreload is not loading all authors.\r\n\r\n### Expected behavior\r\n\r\nPreload loads all authors."}}
{"actor":{"display_login":"josevalim"}}