Hi, I have this notifications table which basically has a userid and a msg (notification).

What should I do with the userid? I would like to look up the user by name and stick the id in the table.

Is that normally what you’d do in this case? A dropdown list would be too large.



When (how often) would you want to get the user's name? That's the question I would ask before deciding whether to denormalize this or not.

If you're just doing a listing on a table, you could do Notification.includes(:user).where ... and that would lazy-load the users for you, so you could get the user's name without an N+1 lookup. If you are showing the user all of their notifications, then you would be doing something like current_user.notifications ... so you would have the user already that way.

The answer to your question depends on the context.


ok, the context is I have this table to update users with small notifications messages.

Rails scaffold generated a userid and msg form. Now, when I need to send a user a message I look them up in the table, grab their id and then put the id in the field along with a message.