1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/models
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
..
admin Update prefix and allow suffix options for store accessors 2018-06-12 07:10:09 -07:00
autoloadable Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
publisher Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
account.rb Generate delegation methods to named scope in the definition time 2018-10-09 13:03:08 +09:00
admin.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
aircraft.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
arunit2_model.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
author.rb Fix test that was broken by adding a default scope to an existing model 2019-02-26 21:58:42 -05:00
auto_id.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
binary.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
bird.rb Revert "Merge pull request #35186 from kamipo/fix_leaking_scope_on_relation_create" 2019-02-15 12:06:45 +09:00
book.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
boolean.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
bulb.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
cake_designer.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
car.rb Fix touch option to behave consistently with Persistence#touch method 2018-06-18 19:08:41 +09:00
carrier.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
cat.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
categorization.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
category.rb Fix reset of the source association when through association is loaded 2019-02-20 13:48:51 +02:00
chef.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
citation.rb Eager loading/preloading should be worked regardless of large number of records 2018-09-12 01:11:38 +09:00
club.rb More exercise singular association query 2018-11-28 03:34:20 +09:00
college.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
column.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
column_name.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
comment.rb Deprecate update_attributes and update_attributes! 2018-02-17 13:58:54 -08:00
company.rb Fix pluck and select with custom attributes 2019-02-13 02:47:46 +09:00
company_in_module.rb allow table name and direction in string order arg 2017-11-09 22:41:33 +10:30
computer.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
contact.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
content.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
contract.rb Fix pluck and select with custom attributes 2019-02-13 02:47:46 +09:00
country.rb create_table with :primary_key option has no effect if id: false is given 2018-10-27 22:57:16 +09:00
course.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
customer.rb Remove unused/missing to_money converter in the test/doc 2018-01-29 16:45:29 +09:00
customer_carrier.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
dashboard.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
default.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
department.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
developer.rb Allow returning nil for default_scope 2019-02-28 00:24:23 +09:00
dog.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
dog_lover.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
doubloon.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
drink_designer.rb Refs #28025 nullify *_type column on polymorphic associations on :nu… (#28078) 2019-01-15 23:03:20 +09:00
edge.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
electron.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
engine.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
entrant.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
essay.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
event.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
eye.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
face.rb Make reflection.klass raise if polymorphic? not to be misused 2018-02-19 00:11:29 +09:00
family.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
family_tree.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
friendship.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
frog.rb Merge pull request #30956 from CJStadler/with-lock-changed-deprecation 2018-03-28 13:11:01 -04:00
guid.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
guitar.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
hotel.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
image.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
interest.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
invoice.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
item.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
job.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
joke.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
keyboard.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
legacy_thing.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
lesson.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
line_item.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
liquid.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
man.rb Make reflection.klass raise if polymorphic? not to be misused 2018-02-19 00:11:29 +09:00
matey.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
member.rb Ensure to calculate column aliases after all table aliases are constructed 2018-06-19 22:21:51 +09:00
member_detail.rb Using existing models for building multiple has_one through tests 2018-04-22 04:16:44 +09:00
member_type.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
membership.rb allow table name and direction in string order arg 2017-11-09 22:41:33 +10:30
mentor.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
minimalistic.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
minivan.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
mixed_case_monkey.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
molecule.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
movie.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
node.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
non_primary_key.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
notification.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
numeric_data.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
order.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
organization.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
other_dog.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
owner.rb try using regexes 2017-11-09 22:42:15 +10:30
parrot.rb Exercise HABTM fixtures with foreign key constraints 2018-10-30 11:08:41 +09:00
person.rb Refs #28025 nullify *_type column on polymorphic associations on :nu… (#28078) 2019-01-15 23:03:20 +09:00
personal_legacy_thing.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
pet.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
pet_treasure.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
pirate.rb Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
possession.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
post.rb Fixed reselect throwing NoMethodError on ActiveRecord. 2019-03-03 22:25:10 +05:30
price_estimate.rb Fix numericality validator not to be affected by custom getter 2018-08-13 23:28:46 +09:00
professor.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
project.rb try using regexes 2017-11-09 22:42:15 +10:30
publisher.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
randomly_named_c1.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
rating.rb Fix eager loading polymorphic association with mixed table conditions 2019-02-18 00:41:43 +09:00
reader.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
recipe.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
record.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
reference.rb Ensure StatementCache#execute never raises RangeError 2019-01-18 16:01:14 +09:00
reply.rb Revert "Chaining named scope is no longer leaking to class level querying methods" 2019-02-14 05:22:41 +09:00
ship.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
ship_part.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
shop.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
shop_account.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
speedometer.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
sponsor.rb Make reflection.klass raise if polymorphic? not to be misused 2018-02-19 00:11:29 +09:00
string_key_object.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
student.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
subscriber.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
subscription.rb Add regression test for has_many through record creation 2019-02-01 01:34:32 +09:00
tag.rb Fix newly added reflection order when redefining association 2018-01-04 22:55:16 +09:00
tagging.rb Don't update counter cache when through record was not destroyed 2018-01-14 20:46:19 +00:00
task.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
topic.rb Use dedicated Topic model for SerializedAttributeTest 2019-02-28 18:48:01 +09:00
toy.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
traffic_light.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
treasure.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
treaty.rb create_table with :primary_key option has no effect if id: false is given 2018-10-27 22:57:16 +09:00
tree.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
tuning_peg.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
tyre.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
user.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
uuid_child.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
uuid_item.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
uuid_parent.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
vegetables.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
vehicle.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
vertex.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
warehouse_thing.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
wheel.rb Fix touch option to behave consistently with Persistence#touch method 2018-06-18 19:08:41 +09:00
without_table.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
zine.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00