{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1854","repository_url":"https://api.github.com/repos/elixir-ecto/ecto","labels_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1854/labels{/name}","comments_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1854/comments","events_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1854/events","html_url":"https://github.com/elixir-ecto/ecto/pull/1854","id":195574738,"number":1854,"title":"Add new changeset action :ignore","user":{"login":"shhavel","id":1169424,"avatar_url":"https://avatars.githubusercontent.com/u/1169424?v=3","gravatar_id":"","url":"https://api.github.com/users/shhavel","html_url":"https://github.com/shhavel","followers_url":"https://api.github.com/users/shhavel/followers","following_url":"https://api.github.com/users/shhavel/following{/other_user}","gists_url":"https://api.github.com/users/shhavel/gists{/gist_id}","starred_url":"https://api.github.com/users/shhavel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shhavel/subscriptions","organizations_url":"https://api.github.com/users/shhavel/orgs","repos_url":"https://api.github.com/users/shhavel/repos","events_url":"https://api.github.com/users/shhavel/events{/privacy}","received_events_url":"https://api.github.com/users/shhavel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-14T16:15:18Z","updated_at":"2016-12-15T09:11:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/elixir-ecto/ecto/pulls/1854","html_url":"https://github.com/elixir-ecto/ecto/pull/1854","diff_url":"https://github.com/elixir-ecto/ecto/pull/1854.diff","patch_url":"https://github.com/elixir-ecto/ecto/pull/1854.patch"},"body":"Ecto mailing list discussion - https://groups.google.com/forum/#!topic/elixir-ecto/ScPo16tfllc\r\n\r\nWorkaround with `cast_assoc/3` to ignore association with empty parameters:\r\n\r\n```elixir\r\ndefmodule Post do\r\n  use Ecto.Schema\r\n  import Ecto.Changeset\r\n\r\n  schema \"posts\" do\r\n    field :title, :string\r\n    field :body, :string\r\n    has_many :comments, Comment\r\n  end\r\n\r\n  def changeset(post, params) do\r\n    cast(post, params, [:title, :body])\r\n    |> cast_assoc(:comments, with: &Comment.changeset_ignored_without_required_fields/2)\r\n  end\r\nend\r\n\r\ndefmodule Comment do\r\n  use Ecto.Schema\r\n  import Ecto.Changeset\r\n\r\n  schema \"comments\" do\r\n    field :body, :string\r\n    belongs_to :post, Post\r\n  end\r\n\r\n  def changeset_ignored_without_required_fields(comment, params) do\r\n    cast(comment, params, [:body])\r\n    |> maybe_ignore\r\n  end\r\n\r\n  defp maybe_ignore(%{changes: %{body: body}} = changeset) when is_nil(body) or body == \"\" do\r\n    %{changeset | action: :ignored}\r\n  end\r\n  defp maybe_ignore(changeset) do\r\n    changeset\r\n  end\r\nend\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/elixir-ecto/ecto/issues/comments/267275619","html_url":"https://github.com/elixir-ecto/ecto/pull/1854#issuecomment-267275619","issue_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1854","id":267275619,"user":{"login":"shhavel","id":1169424,"avatar_url":"https://avatars.githubusercontent.com/u/1169424?v=3","gravatar_id":"","url":"https://api.github.com/users/shhavel","html_url":"https://github.com/shhavel","followers_url":"https://api.github.com/users/shhavel/followers","following_url":"https://api.github.com/users/shhavel/following{/other_user}","gists_url":"https://api.github.com/users/shhavel/gists{/gist_id}","starred_url":"https://api.github.com/users/shhavel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shhavel/subscriptions","organizations_url":"https://api.github.com/users/shhavel/orgs","repos_url":"https://api.github.com/users/shhavel/repos","events_url":"https://api.github.com/users/shhavel/events{/privacy}","received_events_url":"https://api.github.com/users/shhavel/received_events","type":"User","site_admin":false},"created_at":"2016-12-15T09:11:02Z","updated_at":"2016-12-15T09:11:02Z","body":"OK, sorry, I need some time to understand how option `:on_replace` in `Ecto.Changeset.Relation` works to implement `:ignored` by analogy with it."}}
{"actor":{"display_login":"shhavel"}}