notifications

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

notifications

Joe Guerra
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f2e33535-119a-496f-ada2-7502d9826833%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: notifications

Walter Lee Davis


> On May 29, 2017, at 1:34 PM, Joe Guerra <[hidden email]> 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.

Walter

--
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 [hidden email].
To post to this group, send email to [hidden email].
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 | Threaded
Open this post in threaded view
|

Re: notifications

Joe Guerra
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

On Mon, May 29, 2017 at 1:55 PM, Walter Lee Davis <[hidden email]> wrote:


> On May 29, 2017, at 1:34 PM, Joe Guerra <[hidden email]> 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.

Walter

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAOFgAMmUzgxCuHFoOVk%3DCxDn6%3D63mjoXwEAa_rfPrCS9oCBxaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.