notifications

14 views
Skip to first unread message

Joe Guerra

unread,
May 29, 2017, 1:34:39 PM5/29/17
to Ruby on Rails: Talk
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

Walter Lee Davis

unread,
May 29, 2017, 1:55:49 PM5/29/17
to rubyonra...@googlegroups.com
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.

Walter

Joe Guerra

unread,
May 29, 2017, 2:01:17 PM5/29/17
to rubyonra...@googlegroups.com
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.

Thanks,
Joe


--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/C910C1AA-AECA-4A2E-844A-C116B88A8796%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages