Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe that it would be customary and acceptable in this case to use <code>:include</code> instead of <code>:join</code>. I think that <code>:join</code> is only used in rare specialized circumstances, whereas <code>:include</code> is pretty common.</p> <p>If you're not going to be updating all of the active users, then it's probably wise to add an additional named scope or find condition to further narrow down which users you're loading so that you're not loading extra users &amp; subscriptions unnecessarily. For instance...</p> <pre><code>User.active.some_further_limiting_scope(:with_an_argument) #or User.active.find(:all, :conditions =&gt; {:etc =&gt; 'etc'}) </code></pre> <p>If you decide that you still want to use the <code>:join</code>, and are only going to update a small percentage of the loaded users, then it's probably best to reload just the user you want to update right before doing so. Such as...</p> <pre><code>readonly_users = User.active # insert some other code that picks out a particular user to update User.find(readonly_users[@index].id).update_attributes(:etc =&gt; 'etc') </code></pre> <p>If you really do need to load <em>all</em> active users, and you want to stick with the <code>:join</code>, and you will likely be updating most or all of the users, then your idea to reload them with an array of IDs is probably your best choice.</p> <pre><code>#no need to do find_all_by_id in this case. A simple find() is sufficient. writable_users_without_subscriptions = User.find(Users.active.map(&amp;:id)) </code></pre> <p>I hope that helps. I'm curious which option you go with, or if you found another solution more appropriate for your scenario.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload