Trying to reverse save relations from the target element of a relation, I can add the desired elements to the field and then save the element, but when the edit page reloads the connections aren't there. Doing some digging in the onAfterElementSave() function, I debugged $target->getErrors() to see that one those target elements, because some required fields weren't being specifically set before saving, that the save would field.
I've run into this problem before and the only solution I've found is to loop through all the fields on the element, figure out which are required, then explicitly add those values before attempting to save. It feels like there should be a simpler way around this, and maybe you know one.
Trying to reverse save relations from the target element of a relation, I can add the desired elements to the field and then save the element, but when the edit page reloads the connections aren't there. Doing some digging in the
onAfterElementSave()
function, I debugged$target->getErrors()
to see that one those target elements, because some required fields weren't being specifically set before saving, that the save would field.I've run into this problem before and the only solution I've found is to loop through all the fields on the element, figure out which are required, then explicitly add those values before attempting to save. It feels like there should be a simpler way around this, and maybe you know one.