instance method annotate

Ruby on Rails 7.0.10

Since v6.0.6

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

Signature

annotate(*args)

Adds an SQL comment to queries generated from this relation. For example:

User.annotate("selecting user names").select(:name)
# SELECT "users"."name" FROM "users" /* selecting user names */

User.annotate("selecting", "user", "names").select(:name)
# SELECT "users"."name" FROM "users" /* selecting */ /* user */ /* names */

The SQL block comment delimiters, “/*” and “*/”, will be added automatically.

Some escaping is performed, however untrusted user input should not be used.

Parameters

args rest
Source
# File activerecord/lib/active_record/relation/query_methods.rb, line 1239
    def annotate(*args)
      check_if_method_has_arguments!(__callee__, args)
      spawn.annotate!(*args)
    end

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

Defined in ActiveRecord::QueryMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close