instance method ordered_relation

Ruby on Rails 8.1.2

Since v5.2.8.1 Private

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

ordered_relation()

No documentation comment.

Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 641
      def ordered_relation
        if order_values.empty?
          if !_order_columns.empty?
            return order(_order_columns.map { |column| table[column].asc })
          end

          if ActiveRecord.raise_on_missing_required_finder_order_columns
            raise MissingRequiredOrderError, <<~MSG.squish
              Relation has no order values, and #{model} has no order columns to use as a default.
              Set at least one of `implicit_order_column`, `query_constraints` or `primary_key` on
              the model when no `order `is specified on the relation.
            MSG
          else
            ActiveRecord.deprecator.warn(<<~MSG)
              Calling order dependent finder methods (e.g. `#first`, `#second`) without `order` values on the relation,
              and on a model (#{model}) that does not have any order columns (`implicit_order_column`, `query_constraints`,
              or `primary_key`) to fall back on is deprecated and will raise `ActiveRecord::MissingRequiredOrderError`
              in Rails 8.2.
            MSG

            self
          end
        else
          self
        end
      end

Defined in activerecord/lib/active_record/relation/finder_methods.rb line 641 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::FinderMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close