I have a model Candidate, which might has_many model Address
So I made a nested_form for editing candidate & associated addresses
We used Sentry to catch bug, it keep showing a weird bugs like this
Elixir.RuntimeError
you are attempting to change relation :addresses of Candidates.Candidate but the :on_replace
option of
this relation is set to :raise
.
By default it is not possible to replace or delete embeds and
associations during cast
. Therefore Ecto requires all existing
data to be given on update. Failing to do so results in this
error message.
And it logs the params to be like this, so when I edit candidate I also can add a new address to him/her
{
“_utf8”:Preformatted text
“✓”,
“_csrf_token”: “Fj1IGGMYKFNZCjINBw1nEXkeKy0DEAAAZUpYSomxr2e9RT4P7VXypQ==”,
“id”: “801a2392-73c7-4864-a2e2-c0f9b2d89b3c”,
“candidate”: {
“phones”: {
“0”: {
“type”: “mobile”,
“number”: “+3843243543534”,
“id”: “62e353e1-4b8c-422e-bdbd-27a6214f9d98”,
“delete”: “false”
}
},
“nested_model_id”: “”,
“form_partial”: “contact_info”,
“addresses”: {
“1522084910323”: {
“city”: “Odessa”,
“street1”: “ABC”,
“street2”: “”,
“country_id”: “a668d02e-3ca2-4833-b665-f830d23a59bd”,
“state_id”: “f286048c-6678-47fa-9476-9df4f47c7b52”,
“address_type”: “Home”,
“zip_code”: “65123”
}
},
“email”: "abcde@ghi.com"
},
“_method”: “put”
}
The thing is the bug is only catched in Sentry, in production enviroment and I don’t know how it happen, and can not reproduce it on my machine, everything work just fine on my machine or my team’s machine.
We’re stuck at this, anyone have any clue about this problem?`