Proper way to prevent ActiveRecord::ReadOnlyRecord?

后端 未结 4 897
执念已碎
执念已碎 2021-01-03 19:03

I\'m currently using Rails 2.3.9. I understand that specifying the :joins option in a query without an explicit :select automatically makes any re

4条回答
  •  天命终不由人
    2021-01-03 19:13

    I ran across this same issue and was not comfortable using :readonly => false

    As a result I did an explicit select namely :select => 'users.*' and felt that it seemed like less of a hack.

    You could consider doing the following:

    class User < ActiveRecord::Base
      has_one :subscription
    
      named_scope :active, :select => 'users.*', :conditions => { :subscriptions => { :status => 'active' } }, :joins => :subscription
    end
    

提交回复
热议问题