{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/433","labels_url":"https://api.github.com/repos/elixir-lang/ecto/issues/433/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/ecto/issues/433/comments","events_url":"https://api.github.com/repos/elixir-lang/ecto/issues/433/events","html_url":"https://github.com/elixir-lang/ecto/pull/433","id":56867887,"number":433,"title":"Composable casts","user":{"login":"whatyouhide","id":3890250,"avatar_url":"https://avatars.githubusercontent.com/u/3890250?v=3","gravatar_id":"","url":"https://api.github.com/users/whatyouhide","html_url":"https://github.com/whatyouhide","followers_url":"https://api.github.com/users/whatyouhide/followers","following_url":"https://api.github.com/users/whatyouhide/following{/other_user}","gists_url":"https://api.github.com/users/whatyouhide/gists{/gist_id}","starred_url":"https://api.github.com/users/whatyouhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whatyouhide/subscriptions","organizations_url":"https://api.github.com/users/whatyouhide/orgs","repos_url":"https://api.github.com/users/whatyouhide/repos","events_url":"https://api.github.com/users/whatyouhide/events{/privacy}","received_events_url":"https://api.github.com/users/whatyouhide/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-06T21:04:35Z","updated_at":"2015-02-07T12:39:45Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/elixir-lang/ecto/pulls/433","html_url":"https://github.com/elixir-lang/ecto/pull/433","diff_url":"https://github.com/elixir-lang/ecto/pull/433.diff","patch_url":"https://github.com/elixir-lang/ecto/pull/433.patch"},"body":"This should close #401.\r\n\r\nThis PR adds the possibility of composing casts by making `Ecto.Changeset.cast/4` accept a changeset instead of a model as its second argument:\r\n\r\n```elixir\r\nchangeset = cast(%{title: \"Title\"}, %Post{}, ~w(title), ~w())\r\ncast(%{title: \"Foo\", body: \"Bar\"}, changeset, ~w(title), ~w(body))\r\n```\r\n\r\nI think the nicest solution (and the one I've implemented) is to apply the new \"cast\" to the model in the argument changeset (in the example, `changeset.model`) and then to meticulously merge the argument changeset and the new changeset (I added the `merge_changesets/2` function for that).\r\n\r\nAnother way to implement this would have been to manually call `cast` with the model in the argument changeset and with merged title, options and params) but that way an already applied cast is just re-applied another time; maybe this solution is nicer though, so I'm more than willing to change the implementation (I could `push --force` just the second commit) if so.\r\n\r\nThanks! :smiley: "},"comment":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/comments/73362739","html_url":"https://github.com/elixir-lang/ecto/pull/433#issuecomment-73362739","issue_url":"https://api.github.com/repos/elixir-lang/ecto/issues/433","id":73362739,"user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"created_at":"2015-02-07T12:39:45Z","updated_at":"2015-02-07T12:39:45Z","body":"Beautiful. I have added just one tiny comment!"}}