title: Proper way to prevent ActiveRecord::ReadOnlyRecord?
body: <p>I'm currently using Rails 2.3.9.  I understand that specifying the <code>:joins</code> option in a query without an explicit <code>:select</code> automatically makes any records that are returned read-only.  I have a situation where I would like to update the records and while I've read about different ways to approach it, I was wondering which way is the preferred or "proper" way.</p>
  
  <p>Specifically, my situation is that I have the following <code>User</code> model with an <code>active</code> named scope that performs a JOIN with the <code>subscriptions</code> table:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_one :subscription
  
    named_scope :active, :conditions =&gt; { :subscriptions =&gt; { :status =&gt; 'active' } }, :joins =&gt; :subscription
  end
  </code></pre>
  
  <p>When I call <code>User.active.all</code>, the user records that are returned are all read-only, so if, for instance, I call <code>update_attributes!</code> on a user, <code>ActiveRecord::ReadOnlyRecord</code> will be raised.</p>
  
  <p>Through reading various sources, it seems a popular way to get around this is by adding <code>:readonly =&gt; false</code> to the query.  However, I was wondering the following:</p>
  
  <ul>
  <li><strong>Is this safe?</strong>  I understand the reason why Rails sets it to read-only in the first place is because, according to the <a href="http://apidock.com/rails/ActiveRecord/Base/find/class" rel="nofollow noreferrer">Rails documentation</a>, "they will have attributes that do not correspond to the table’s columns."  However, the SQL query that is generated from this call uses <code>SELECT `users`.*</code> anyway, which appears to be safe, <strong>so what is Rails trying to guard against in the first place?</strong>  It would appear that Rails should be guarding against the case when <code>:select</code> is actually explicitly specified, which is the reverse of the actual behavior, <strong>so am I not properly understanding the purpose of automatically setting the read-only flag on <code>:joins</code>?</strong></li>
  <li><strong>Does this seem like a hack?</strong>  It doesn't seem proper that the definition of a named scope should care about explicitly setting <code>:readonly =&gt; false</code>.  I'm also afraid of side effects if the named scoped is chained with other named scopes.  If I try to specify it outside of the scope (e.g., by doing <code>User.active.scoped(:readonly =&gt; false)</code> or <code>User.scoped(:readonly =&gt; false).active</code>), it doesn't appear to work.</li>
  </ul>
  
  <p>One other way I've read to get around this is to change the <code>:joins</code> to an <code>:include</code>.  I understand the behavior of this better, but <strong>are there any disadvantages to this (other than the unnecessary reading of all the columns in the <code>subscriptions</code> table)?</strong></p>
  
  <p>Lastly, I could also retrieve the query again using the record IDs by calling <code>User.find_all_by_id(User.active.map(&amp;:id))</code>, but I find this to be more of a workaround rather than a possible solution since it generates an extra SQL query.</p>
  
  <p><strong>Are there any other possible solutions?  What would be the preferred solution in this situation?</strong>  I've read the answer given in the <a href="https://stackoverflow.com/questions/639171/what-is-causing-this-activerecordreadonlyrecord-error">previous StackOverflow question about this</a>, but it doesn't seem to give specific guidance of what would be considered correct.</p>
  
  <p>Thanks in advance!</p>