Repository: rails/rails
File: activerecord/lib/active_record/model_schema.rb (Ruby)

Code before:

      # The array of names of environments where destructive actions should be prohibited. By default,
      # the value is <tt>["production"]</tt>.
      def protected_environments
        if defined?(@protected_environments)
          @protected_environments
        else
          superclass.protected_environments
        end
      end

      # Sets an array of names of environments where destructive actions should be prohibited.
      def protected_environments=(environments)
        @protected_environments = environments.map(&:to_s)
      end

      def real_inheritance_column=(value) # :nodoc:
        self._inheritance_column = value.to_s
      end

      # The list of columns names the model should ignore. Ignored columns won't have attribute
      # accessors defined, and won't be referenced in SQL queries.
      def ignored_columns
        return @ignored_columns if @ignored_columns
        return superclass.ignored_columns if superclass.respond_to?(:ignored_columns)
        return column_names - @permitted_columns if schema_loaded? && @permitted_columns.present?

        []
      end

      # The list of columns names the model should allow. Permitted columns are used to define
      # attribute accessors, and are referenced in SQL queries.
      def permitted_columns
        return @permitted_columns if @permitted_columns
        return superclass.permitted_columns if superclass.respond_to?(:permitted_columns)
        return column_names - @ignored_columns if schema_loaded? && @ignored_columns.present?

        []
      end

      # Sets the columns names the model should ignore. Ignored columns won't have attribute
      # accessors defined, and won't be referenced in SQL queries.
      #
      # A common usage pattern for this method is to ensure all references to an attribute
      # have been removed and deployed, before a migration to drop the column from the database
      # has been deployed and run. Using this two step approach to dropping columns ensures there
      # is no code that raises errors due to having a cached schema in memory at the time the
      # schema migration is run.
      #
      # For example, given a model where you want to drop the "category" attribute, first mark it
      # as ignored:

Review comment (suggestion):
We should avoid having different behavior based on whether the schema is loaded or not. I don't think this is necessary at all.


Code after:

      # The array of names of environments where destructive actions should be prohibited. By default,
      # the value is <tt>["production"]</tt>.
      def protected_environments
        if defined?(@protected_environments)
          @protected_environments
        else
          superclass.protected_environments
        end
      end

      # Sets an array of names of environments where destructive actions should be prohibited.
      def protected_environments=(environments)
        @protected_environments = environments.map(&:to_s)
      end

      def real_inheritance_column=(value) # :nodoc:
        self._inheritance_column = value.to_s
      end

      # The list of columns names the model should ignore. Ignored columns won't have attribute
      # accessors defined, and won't be referenced in SQL queries.
      def ignored_columns
        @ignored_columns || superclass.ignored_columns
      end

      # The list of columns names the model should allow. Only columns are used to define
      # attribute accessors, and are referenced in SQL queries.
      def only_columns
        @only_columns || superclass.only_columns
      end

      # Sets the columns names the model should ignore. Ignored columns won't have attribute
      # accessors defined, and won't be referenced in SQL queries.
      #
      # A common usage pattern for this method is to ensure all references to an attribute
      # have been removed and deployed, before a migration to drop the column from the database
      # has been deployed and run. Using this two step approach to dropping columns ensures there
      # is no code that raises errors due to having a cached schema in memory at the time the
      # schema migration is run.
      #
      # For example, given a model where you want to drop the "category" attribute, first mark it
      # as ignored:
      #
      #   class Project < ActiveRecord::Base
      #     # schema:
      #     #   id         :bigint
      #     #   name       :string, limit: 255
      #     #   category   :string, limit: 255
      #
      #     self.ignored_columns += [:category]