{"action":"created","comment":{"url":"https://api.github.com/repos/elixir-ecto/ecto/pulls/comments/130377463","pull_request_review_id":53245378,"id":130377463,"diff_hunk":"@@ -1405,10 +1412,44 @@ defmodule Ecto.Schema do\n   defp type_to_module(:utc_datetime), do: DateTime\n   defp type_to_module(other), do: other\n \n+  defp replace_field_sources(fields = %{}, aliases) do\n+    Enum.reduce(fields, %{}, fn\n+      {field, value}, acc ->\n+        field = case is_atom(field) do\n+                  true -> field\n+                  false -> String.to_atom(field)\n+                end\n+\n+        field_name = case List.keyfind(aliases, field, 1) do\n+                       {aliased, _} -> to_string(aliased)\n+                       nil -> field\n+                     end\n+\n+        Map.put(acc, field_name, value)\n+    end)\n+  end\n+  defp replace_field_sources({fields, values}, aliases) do\n+    {replace_field_sources(fields, [], aliases), values}\n+  end\n+  defp replace_field_sources([field|fields], list, aliases) do\n+    field = case List.keyfind(aliases, field, 1) do\n+              {field, _} -> field\n+              _ -> field\n+            end\n+\n+    replace_field_sources(fields, list ++ [field], aliases)\n+  end\n+  defp replace_field_sources([], list, _aliases) do\n+    list\n+  end\n+\n   @doc false\n   def __load__(schema, prefix, source, context, data, loader) do\n     struct = schema.__struct__()\n     types = schema.__schema__(:types)\n+    aliases = schema.__schema__(:aliases)\n+\n+    data = replace_field_sources(data, aliases)","path":"lib/ecto/schema.ex","position":null,"original_position":120,"commit_id":"b6f5f36250056aecb37ced05113fce48d5c0d16a","original_commit_id":"828c6b6a55098c9c43f91badf5425fa4c55e1a55","user":{"login":"michalmuskala","id":477062,"avatar_url":"https://avatars0.githubusercontent.com/u/477062?v=4","gravatar_id":"","url":"https://api.github.com/users/michalmuskala","html_url":"https://github.com/michalmuskala","followers_url":"https://api.github.com/users/michalmuskala/followers","following_url":"https://api.github.com/users/michalmuskala/following{/other_user}","gists_url":"https://api.github.com/users/michalmuskala/gists{/gist_id}","starred_url":"https://api.github.com/users/michalmuskala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalmuskala/subscriptions","organizations_url":"https://api.github.com/users/michalmuskala/orgs","repos_url":"https://api.github.com/users/michalmuskala/repos","events_url":"https://api.github.com/users/michalmuskala/events{/privacy}","received_events_url":"https://api.github.com/users/michalmuskala/received_events","type":"User","site_admin":false},"body":"No load is called every time we load data from the database - it's responsible for putting the raw data into schemas with proper types.","created_at":"2017-07-31T14:59:51Z","updated_at":"2017-07-31T14:59:51Z","html_url":"https://github.com/elixir-ecto/ecto/pull/1998#discussion_r130377463","pull_request_url":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998","_links":{"self":{"href":"https://api.github.com/repos/elixir-ecto/ecto/pulls/comments/130377463"},"html":{"href":"https://github.com/elixir-ecto/ecto/pull/1998#discussion_r130377463"},"pull_request":{"href":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998"}}},"pull_request":{"url":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998","id":111532118,"html_url":"https://github.com/elixir-ecto/ecto/pull/1998","diff_url":"https://github.com/elixir-ecto/ecto/pull/1998.diff","patch_url":"https://github.com/elixir-ecto/ecto/pull/1998.patch","issue_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1998","number":1998,"state":"open","locked":false,"title":"Add :source option for schema `field`","user":{"login":"Bharat311","id":1005808,"avatar_url":"https://avatars1.githubusercontent.com/u/1005808?v=4","gravatar_id":"","url":"https://api.github.com/users/Bharat311","html_url":"https://github.com/Bharat311","followers_url":"https://api.github.com/users/Bharat311/followers","following_url":"https://api.github.com/users/Bharat311/following{/other_user}","gists_url":"https://api.github.com/users/Bharat311/gists{/gist_id}","starred_url":"https://api.github.com/users/Bharat311/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bharat311/subscriptions","organizations_url":"https://api.github.com/users/Bharat311/orgs","repos_url":"https://api.github.com/users/Bharat311/repos","events_url":"https://api.github.com/users/Bharat311/events{/privacy}","received_events_url":"https://api.github.com/users/Bharat311/received_events","type":"User","site_admin":false},"body":"This PR adds a `source` option to `field`.\r\n\r\nThe `source` name is then used within the database, whereas the name provided with `field` is used to refer to that field in the codebase.\r\n\r\nRefer #1892  for more details.\r\n\r\n### TODO:\r\n\r\n- [x] Insertion\r\n- [x] Updation\r\n- [x] Deletion\r\n- [x] Reading\r\n- [x] Quering\r\n- [x] Error Reporting\r\n- [x] Uniqueness\r\n- [x] Embedded Schema\r\n- [x] Tests\r\n","created_at":"2017-03-20T11:26:47Z","updated_at":"2017-07-31T14:59:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0c8b5b908c8931a6cc031b471dcb33c24149cdf8","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998/commits","review_comments_url":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998/comments","review_comment_url":"https://api.github.com/repos/elixir-ecto/ecto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1998/comments","statuses_url":"https://api.github.com/repos/elixir-ecto/ecto/statuses/b6f5f36250056aecb37ced05113fce48d5c0d16a","head":{"label":"Bharat311:f-alias","ref":"f-alias","sha":"b6f5f36250056aecb37ced05113fce48d5c0d16a","user":{"login":"Bharat311","id":1005808,"avatar_url":"https://avatars1.githubusercontent.com/u/1005808?v=4","gravatar_id":"","url":"https://api.github.com/users/Bharat311","html_url":"https://github.com/Bharat311","followers_url":"https://api.github.com/users/Bharat311/followers","following_url":"https://api.github.com/users/Bharat311/following{/other_user}","gists_url":"https://api.github.com/users/Bharat311/gists{/gist_id}","starred_url":"https://api.github.com/users/Bharat311/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bharat311/subscriptions","organizations_url":"https://api.github.com/users/Bharat311/orgs","repos_url":"https://api.github.com/users/Bharat311/repos","events_url":"https://api.github.com/users/Bharat311/events{/privacy}","received_events_url":"https://api.github.com/users/Bharat311/received_events","type":"User","site_admin":false},"repo":{"id":84942184,"name":"ecto","full_name":"Bharat311/ecto","owner":{"login":"Bharat311","id":1005808,"avatar_url":"https://avatars1.githubusercontent.com/u/1005808?v=4","gravatar_id":"","url":"https://api.github.com/users/Bharat311","html_url":"https://github.com/Bharat311","followers_url":"https://api.github.com/users/Bharat311/followers","following_url":"https://api.github.com/users/Bharat311/following{/other_user}","gists_url":"https://api.github.com/users/Bharat311/gists{/gist_id}","starred_url":"https://api.github.com/users/Bharat311/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bharat311/subscriptions","organizations_url":"https://api.github.com/users/Bharat311/orgs","repos_url":"https://api.github.com/users/Bharat311/repos","events_url":"https://api.github.com/users/Bharat311/events{/privacy}","received_events_url":"https://api.github.com/users/Bharat311/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Bharat311/ecto","description":"A database wrapper and language integrated query for Elixir","fork":true,"url":"https://api.github.com/repos/Bharat311/ecto","forks_url":"https://api.github.com/repos/Bharat311/ecto/forks","keys_url":"https://api.github.com/repos/Bharat311/ecto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bharat311/ecto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bharat311/ecto/teams","hooks_url":"https://api.github.com/repos/Bharat311/ecto/hooks","issue_events_url":"https://api.github.com/repos/Bharat311/ecto/issues/events{/number}","events_url":"https://api.github.com/repos/Bharat311/ecto/events","assignees_url":"https://api.github.com/repos/Bharat311/ecto/assignees{/user}","branches_url":"https://api.github.com/repos/Bharat311/ecto/branches{/branch}","tags_url":"https://api.github.com/repos/Bharat311/ecto/tags","blobs_url":"https://api.github.com/repos/Bharat311/ecto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bharat311/ecto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bharat311/ecto/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bharat311/ecto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bharat311/ecto/statuses/{sha}","languages_url":"https://api.github.com/repos/Bharat311/ecto/languages","stargazers_url":"https://api.github.com/repos/Bharat311/ecto/stargazers","contributors_url":"https://api.github.com/repos/Bharat311/ecto/contributors","subscribers_url":"https://api.github.com/repos/Bharat311/ecto/subscribers","subscription_url":"https://api.github.com/repos/Bharat311/ecto/subscription","commits_url":"https://api.github.com/repos/Bharat311/ecto/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bharat311/ecto/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bharat311/ecto/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bharat311/ecto/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bharat311/ecto/contents/{+path}","compare_url":"https://api.github.com/repos/Bharat311/ecto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bharat311/ecto/merges","archive_url":"https://api.github.com/repos/Bharat311/ecto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bharat311/ecto/downloads","issues_url":"https://api.github.com/repos/Bharat311/ecto/issues{/number}","pulls_url":"https://api.github.com/repos/Bharat311/ecto/pulls{/number}","milestones_url":"https://api.github.com/repos/Bharat311/ecto/milestones{/number}","notifications_url":"https://api.github.com/repos/Bharat311/ecto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bharat311/ecto/labels{/name}","releases_url":"https://api.github.com/repos/Bharat311/ecto/releases{/id}","deployments_url":"https://api.github.com/repos/Bharat311/ecto/deployments","created_at":"2017-03-14T11:38:20Z","updated_at":"2017-03-14T11:38:22Z","pushed_at":"2017-07-31T12:48:31Z","git_url":"git://github.com/Bharat311/ecto.git","ssh_url":"git@github.com:Bharat311/ecto.git","clone_url":"https://github.com/Bharat311/ecto.git","svn_url":"https://github.com/Bharat311/ecto","homepage":"https://hexdocs.pm/ecto","size":9282,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elixir-ecto:master","ref":"master","sha":"c32224deae62f78b1cdc493bd9199145141b33be","user":{"login":"elixir-ecto","id":19973437,"avatar_url":"https://avatars3.githubusercontent.com/u/19973437?v=4","gravatar_id":"","url":"https://api.github.com/users/elixir-ecto","html_url":"https://github.com/elixir-ecto","followers_url":"https://api.github.com/users/elixir-ecto/followers","following_url":"https://api.github.com/users/elixir-ecto/following{/other_user}","gists_url":"https://api.github.com/users/elixir-ecto/gists{/gist_id}","starred_url":"https://api.github.com/users/elixir-ecto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elixir-ecto/subscriptions","organizations_url":"https://api.github.com/users/elixir-ecto/orgs","repos_url":"https://api.github.com/users/elixir-ecto/repos","events_url":"https://api.github.com/users/elixir-ecto/events{/privacy}","received_events_url":"https://api.github.com/users/elixir-ecto/received_events","type":"Organization","site_admin":false},"repo":{"id":10649374,"name":"ecto","full_name":"elixir-ecto/ecto","owner":{"login":"elixir-ecto","id":19973437,"avatar_url":"https://avatars3.githubusercontent.com/u/19973437?v=4","gravatar_id":"","url":"https://api.github.com/users/elixir-ecto","html_url":"https://github.com/elixir-ecto","followers_url":"https://api.github.com/users/elixir-ecto/followers","following_url":"https://api.github.com/users/elixir-ecto/following{/other_user}","gists_url":"https://api.github.com/users/elixir-ecto/gists{/gist_id}","starred_url":"https://api.github.com/users/elixir-ecto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elixir-ecto/subscriptions","organizations_url":"https://api.github.com/users/elixir-ecto/orgs","repos_url":"https://api.github.com/users/elixir-ecto/repos","events_url":"https://api.github.com/users/elixir-ecto/events{/privacy}","received_events_url":"https://api.github.com/users/elixir-ecto/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elixir-ecto/ecto","description":"A database wrapper and language integrated query for Elixir","fork":false,"url":"https://api.github.com/repos/elixir-ecto/ecto","forks_url":"https://api.github.com/repos/elixir-ecto/ecto/forks","keys_url":"https://api.github.com/repos/elixir-ecto/ecto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elixir-ecto/ecto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elixir-ecto/ecto/teams","hooks_url":"https://api.github.com/repos/elixir-ecto/ecto/hooks","issue_events_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/events{/number}","events_url":"https://api.github.com/repos/elixir-ecto/ecto/events","assignees_url":"https://api.github.com/repos/elixir-ecto/ecto/assignees{/user}","branches_url":"https://api.github.com/repos/elixir-ecto/ecto/branches{/branch}","tags_url":"https://api.github.com/repos/elixir-ecto/ecto/tags","blobs_url":"https://api.github.com/repos/elixir-ecto/ecto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elixir-ecto/ecto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elixir-ecto/ecto/git/refs{/sha}","trees_url":"https://api.github.com/repos/elixir-ecto/ecto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elixir-ecto/ecto/statuses/{sha}","languages_url":"https://api.github.com/repos/elixir-ecto/ecto/languages","stargazers_url":"https://api.github.com/repos/elixir-ecto/ecto/stargazers","contributors_url":"https://api.github.com/repos/elixir-ecto/ecto/contributors","subscribers_url":"https://api.github.com/repos/elixir-ecto/ecto/subscribers","subscription_url":"https://api.github.com/repos/elixir-ecto/ecto/subscription","commits_url":"https://api.github.com/repos/elixir-ecto/ecto/commits{/sha}","git_commits_url":"https://api.github.com/repos/elixir-ecto/ecto/git/commits{/sha}","comments_url":"https://api.github.com/repos/elixir-ecto/ecto/comments{/number}","issue_comment_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/comments{/number}","contents_url":"https://api.github.com/repos/elixir-ecto/ecto/contents/{+path}","compare_url":"https://api.github.com/repos/elixir-ecto/ecto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elixir-ecto/ecto/merges","archive_url":"https://api.github.com/repos/elixir-ecto/ecto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elixir-ecto/ecto/downloads","issues_url":"https://api.github.com/repos/elixir-ecto/ecto/issues{/number}","pulls_url":"https://api.github.com/repos/elixir-ecto/ecto/pulls{/number}","milestones_url":"https://api.github.com/repos/elixir-ecto/ecto/milestones{/number}","notifications_url":"https://api.github.com/repos/elixir-ecto/ecto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elixir-ecto/ecto/labels{/name}","releases_url":"https://api.github.com/repos/elixir-ecto/ecto/releases{/id}","deployments_url":"https://api.github.com/repos/elixir-ecto/ecto/deployments","created_at":"2013-06-12T18:42:06Z","updated_at":"2017-07-29T18:32:00Z","pushed_at":"2017-07-31T12:48:34Z","git_url":"git://github.com/elixir-ecto/ecto.git","ssh_url":"git@github.com:elixir-ecto/ecto.git","clone_url":"https://github.com/elixir-ecto/ecto.git","svn_url":"https://github.com/elixir-ecto/ecto","homepage":"https://hexdocs.pm/ecto","size":9320,"stargazers_count":2816,"watchers_count":2816,"language":"Elixir","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":679,"mirror_url":null,"open_issues_count":35,"forks":679,"open_issues":35,"watchers":2816,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998"},"html":{"href":"https://github.com/elixir-ecto/ecto/pull/1998"},"issue":{"href":"https://api.github.com/repos/elixir-ecto/ecto/issues/1998"},"comments":{"href":"https://api.github.com/repos/elixir-ecto/ecto/issues/1998/comments"},"review_comments":{"href":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998/comments"},"review_comment":{"href":"https://api.github.com/repos/elixir-ecto/ecto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1998/commits"},"statuses":{"href":"https://api.github.com/repos/elixir-ecto/ecto/statuses/b6f5f36250056aecb37ced05113fce48d5c0d16a"}}}}
{"actor":{"display_login":"michalmuskala"}}