Notification counter is reset if User.last_read_notification is deleted

Example: I follow you. You look at your notifications, and that notification becomes marked read. I unfollow you. The "follow" notification becomes deleted as a result, and now your last_read_notification is null.

User.last_read_notification is a ForeignKey with on_delete: nullify meaning if the notification it points to is deleted, the field will become null. This will essentially reset the counter, showing your total notification count on pageload.

Maybe it shouldn't be a ForeignKey (all it does is compare the value anyway). More on ForeignKey on_delete: https://edgeapi.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_foreign_key

Edited by Alex Gleason