My comments are placed by users. The Comment belongs_to :user and the User has_many :comments.
But users can be removed. If done, I’d rather not delete their comments, but instead associate their comments with one Dummy user.
I can think of several ways:
- On load of a comment, if no associated user is found, create a User in memory with dummy data.
- On load of a comment, if no associated user is found, pick a predefined one from the database.
- On removal of a comment, associate all the comments with a predefined User in the database; through some post filter.
My feeling says that number one is cleanest; since the other two require a user in the database that will be hardwired in the code. If user 18394 will be that “special” user, I’d need all kinds of safetynets for that special user.
What about soft deleting users instead? Have a boolean field called User.active and set a default scope for User.active = t. When a user gets deleted, set the active field to false, and clear out any personal data.