I'm working on a literature community website. (screenshot) And I'm trying to figure out how to notify users when someone comments on something they posted to the site, when someone they are watching submissions a new literature peice, etc.
I'm trying to figure out how to structure the database to store this information. I've come up with two possible ideas.
Store a link to the notifiable object, a field describing the type of action (new, update, etc) that the user is being notified of. This makes for complex display code but it means I can change how notifications work rather easily. This also increase the data I need to pull from the database unless I use a cache field to dump a hash of relevant attributes into the table.
- notifiable_type
- notifiable_id
- user_id
- action
- notifiable_cache (optional, stores a hash of selected attributes from notifiable object)
Treat the notifications like email and just save them to the database with a subject and message. This results in a simple view but a complex model and prevents me from easily changing how notifications work.
- user_id
- title
- message
I'm looking for other ideas and comments on the two I listed above.