Ruby on Rails Monday, May 29, 2017

> On May 29, 2017, at 1:34 PM, Joe Guerra <> wrote:
> 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.
> Thanks,
> Joe

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.


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment