Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing associations when null #66

Open
lxcodes opened this issue Aug 23, 2017 · 1 comment
Open

Removing associations when null #66

lxcodes opened this issue Aug 23, 2017 · 1 comment
Assignees

Comments

@lxcodes
Copy link

lxcodes commented Aug 23, 2017

This may be some what related to #45, but currently it looks like setting parent_id works for both create and update but permitted_attributes isn't getting nil attributes in order to remove them from what I can see. I can remove an association if I directly pass in parent_id => nil in attributes though.

Wondering if this was the intended way to update a resource to remove an association:
PATCH [http://localhost:4000/api/classifications/3]

{
	"data":{
		"id":"3",
		"attributes":{
			"name":"Top Level Classification"
		},
		"relationships":{
			"parent":{
				"data": null
			}
		},
		"type":"classifications"
	}
}

Phoenix Params:

Parameters: %{"data" => %{"attributes" => %{"name" => "Top Level Classification"}, "id" => "3", "relationships" => %{"parent" => %{"data" => nil}}, "type" => "classifications"}, "id" => "3"}

JaResource attrs passed into permitted_attributes:

Before Update Attrs: %{"name" => "Top Level Classification", "type" => "classifications"}

Should there be a "parent_id" => nil there?

Schema:

  schema "classifications" do
    field :name, :string

    belongs_to :parent, Classification, on_replace: :update
    has_many :children, Classification, foreign_key: :parent_id, on_delete: :delete_all

    timestamps()
  end
@psteininger psteininger self-assigned this Jan 22, 2020
@psteininger
Copy link
Collaborator

@lxcodes thanks for filing this. I will take a look at this in the coming days, as I will be working on something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants