rails/guides/source
Matt Yoho f41825809c Add Relation#annotate for SQL commenting
This patch has two main portions:

1. Add SQL comment support to Arel via Arel::Nodes::Comment.
2. Implement a Relation#annotate method on top of that.

== Adding SQL comment support

Adds a new Arel::Nodes::Comment node that represents an optional SQL
comment and teachers the relevant visitors how to handle it.

Comment nodes may be added to the basic CRUD statement nodes and set
through any of the four (Select|Insert|Update|Delete)Manager objects.

For example:

    manager = Arel::UpdateManager.new
    manager.table table
    manager.comment("annotation")
    manager.to_sql # UPDATE "users" /* annotation */

This new node type will be used by ActiveRecord::Relation to enable
query annotation via SQL comments.

== Implementing the Relation#annotate method

Implements `ActiveRecord::Relation#annotate`, which accepts a comment
string that will be appeneded to any queries generated by the relation.

Some examples:

    relation = Post.where(id: 123).annotate("metadata string")
    relation.first
    # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123
    # LIMIT 1 /* metadata string */

    class Tag < ActiveRecord::Base
      scope :foo_annotated, -> { annotate("foo") }
    end
    Tag.foo_annotated.annotate("bar").first
    # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */

Also wires up the plumbing so this works with `#update_all` and
`#delete_all` as well.

This feature is useful for instrumentation and general analysis of
queries generated at runtime.
2019-03-21 20:30:56 -07:00
..
kindle Remove credits.html from Rails Guides 2018-04-03 10:45:03 +09:00
_license.html.erb
_welcome.html.erb Rails guides are now served over https 2018-07-24 11:29:31 +09:00
2_2_release_notes.md Rails guides are now served over https 2018-07-24 11:29:31 +09:00
2_3_release_notes.md Use the HTTPS protocol for links to Edges Guides [ci skip] 2018-08-28 13:49:58 +00:00
3_0_release_notes.md Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
3_1_release_notes.md Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
3_2_release_notes.md Rails guides are now served over https 2018-07-24 11:29:31 +09:00
4_0_release_notes.md Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
4_1_release_notes.md Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
4_2_release_notes.md Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
5_0_release_notes.md Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
5_1_release_notes.md Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
5_2_release_notes.md Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
6_0_release_notes.md Added release notes for changes in Railties [ci skip] (#35622) 2019-03-18 22:41:53 +05:30
action_cable_overview.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
action_controller_overview.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
action_mailbox_basics.md Add Exim and Qmail support to Action Mailbox 2019-01-12 21:38:26 -05:00
action_mailer_basics.md - Remove the word painfully from documentation 2019-03-08 11:14:49 -08:00
action_text_overview.md Add Action Text to guides [ci skip] 2019-01-05 13:30:37 +02:00
action_view_overview.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
active_job_basics.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
active_model_basics.md Rails guides are now served over https 2018-07-24 11:29:31 +09:00
active_record_basics.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
active_record_callbacks.md update callbacks skipping methods in guide [ci skip] 2019-02-23 01:22:53 +05:30
active_record_migrations.md Replace “can not” with “cannot”. 2019-03-06 16:35:52 -05:00
active_record_postgresql.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
active_record_querying.md Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
active_record_validations.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
active_storage_overview.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
active_support_core_extensions.md Update multiline? sample code [ci skip] 2019-03-07 23:53:07 +09:00
active_support_instrumentation.md Add mention about process_middleware.action_dispatch in the guide [ci skip] 2019-03-20 05:20:15 +00:00
api_app.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
api_documentation_guidelines.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
asset_pipeline.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
association_basics.md Add note about has_many associations callbacks [ci skip] 2019-03-12 10:28:31 +00:00
autoloading_and_reloading_constants.md [ci skip] Minor documentation fixes for consistency 2019-03-09 12:15:00 +05:30
caching_with_rails.md Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
command_line.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
configuring.md Revert "Revert "Remove javascripts and javascript_engine options for generators"" 2019-03-20 09:48:51 +09:00
contributing_to_ruby_on_rails.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
debugging_rails_applications.md Fix typo 2018-11-05 08:46:44 +13:00
development_dependencies_install.md Fix "Development Dependencies Install" guide [ci skip] 2019-01-19 23:28:25 +00:00
documents.yaml Add Action Text to guides [ci skip] 2019-01-05 13:30:37 +02:00
engines.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
form_helpers.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
generators.md Remove mentions about javascripts option from the guide about generators [ci skip] 2018-10-22 23:55:36 +03:00
getting_started.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
i18n.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
index.html.erb Add OG tags to layout.html.erb 2019-01-09 13:23:22 +09:00
initialization.md Rails guides are now served over https 2018-07-24 11:29:31 +09:00
layout.html.erb Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
layouts_and_rendering.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
maintenance_policy.md Rails guides are now served over https 2018-07-24 11:29:31 +09:00
plugins.md Merge pull request #33229 from albertoalmagro/albertoalmagro/prefer-rails-command-over-bin-rails 2018-07-25 04:10:29 +09:30
rails_application_templates.md Abort early if generator command fails (#34420) 2018-12-07 15:01:32 +09:00
rails_on_rack.md Changed webserver to web server. 2019-01-22 21:11:03 +05:30
routing.md [ci skip] Removed extra hyphens 2019-03-11 19:31:36 +05:30
ruby_on_rails_guides_guidelines.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
security.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
testing.md [ci skip] Minor documentation fixes for consistency 2019-03-09 12:15:00 +05:30
threading_and_code_execution.md Rails guides are now served over https 2018-07-24 11:29:31 +09:00
upgrading_ruby_on_rails.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
working_with_javascript_in_rails.md Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00