Skip to content

Instantly share code, notes, and snippets.

@kazuhisa
Created September 11, 2013 14:57
Show Gist options
  • Save kazuhisa/6524819 to your computer and use it in GitHub Desktop.
Save kazuhisa/6524819 to your computer and use it in GitHub Desktop.
Rails4.0.0でJoinしたテーブルに対してreadonly(false)が効かないのはバグです。4.1系で解消されるはずなので、次のパッチをconfig/initializersにでも入れておくといいよ。
# -*- coding: utf-8 -*-
module ActiveRecord
class Relation
def initialize(klass, table, values = {})
@klass = klass
@table = table
@values = values
@loaded = false
end
private
def exec_queries
@records = eager_loading? ? find_with_associations : @klass.find_by_sql(arel, bind_values)
preload = preload_values
preload += includes_values unless eager_loading?
preload.each do |associations|
ActiveRecord::Associations::Preloader.new(@records, associations).run
end
@records.each { |record| record.readonly! } if readonly_value
@loaded = true
@records
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment