Resolve "Add missing `dependent: :nullify` on User for `has_many: created_projects`"
What does this MR do and why?
See #351064 (comment 1142781154) for more details.
This MR adds the missing dependent: :nullify
clause on User
model, for the association has_many: :created_projects
.
Decision to choose dependent: :nullify
over ON DELETE SET NULL
has been discussed here.
Without this, currently, whenever a User is destroyed, the user.id
of this user still remains in the Project#creator_id
column. And hence, project.creator
always returns nil
and further method calls on project.creator
will fail with NoMethodError: undefined method for nil:NilClass
Once we add dependent: :nullify
, such associations are nullified in batches, whenever a User is destroyed via the Users::DestroyService
class, due to the code here.
We already have ~50k such orphaned Project
records, so the next step is to nullify the creator_id
column of these records using a post deploy migration: #378477 (closed), which will be done in another MR
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #378476 (closed)