Commit Graph

214 Commits

Author SHA1 Message Date
st0012
83ca4a18f7 Add a section to introduce pluck's eager loading behavior 2019-05-03 19:24:53 +08:00
Abhay Nikam
1d5a6a3d8c [ci skip] Add ActiveRecord::Relation#extract_associated method to the active_record_querying.md 2019-03-30 10:14:54 +05:30
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
Ryuta Kamizono
304d82597b Add :reselect and :optimizer_hints to the list of finder methods
These are introduced after Rails 6.0.0 beta2.

[ci skip]
2019-03-18 01:55:17 +09:00
Ryuta Kamizono
6486f80d3a ActiveRecord::Result#to_hash has been renamed to to_a [ci skip]
See #33912.
2019-03-17 03:41:12 +09:00
Ryuta Kamizono
b02a6936f7 Fix incorrect identifier quoting [ci skip] 2019-03-07 17:05:52 +09:00
Ryuta Kamizono
4ad4de50ce Correct the limitation about order with distinct in the guide
That is happened with `distinct`, and that is not only happened on MyS
L, but also on PostgreSQL, SQL Server, and Oracle.

[ci skip]
2019-03-07 12:10:36 +09:00
Nathaniel Suchy
d9f1cc05b5 Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
Andrew White
0c4bf982e8
Merge pull request #33611 from willianveiga/feature/reselect-method
Add reselect method
2019-03-01 08:33:01 +00:00
soartec-lab
2d3d2b7128 How to use select is updated [ci skip] 2019-02-24 11:28:45 +09:00
Gannon McGibbon
7e4eeca370 Clarify scope body requirements
[ci skip]
2018-11-26 16:17:12 -05:00
Willian Gustavo Veiga
4b60e34f58 Mention reselect new method in the "Active Record Query Interface" guide 2018-10-04 21:43:49 -03:00
Andrew
6140d0ca3f
Fix a typo in AR Query Interface [ci skip] 2018-09-18 10:33:46 +03:00
bogdanvlviv
b91dc57928
DRY in Active Record Query Interface [ci skip]
The sentence "This is exactly the same as defining a class method ..."
is not true, so #33653 fixed it, but added changes repeat what is explained
a few lines below. We can remove this part since a user is able to get info
about the difference between scopes and class methods below.

Context https://github.com/rails/rails/pull/33653#discussion_r211105969.

Reverts #33653, 97feb4996b1c88f770101dfce6d4d3a6baf6bb33.
2018-08-19 19:29:41 +03:00
Ryuta Kamizono
97feb4996b Fix syntax error in the doc [ci skip] 2018-08-19 23:35:04 +09:00
LemonAndroid
e2589989d0
Explained difference between scope & class method 2018-08-19 05:07:03 +02:00
Aditya Kapoor
b1b585fe08 [ci skip] Fix the outdated description for find_each. 2018-07-31 13:26:02 +05:30
Paul McMahon
7b9c19d94b Rails guides are now served over https
http links will be redirected to the https version, but still better to
just directly link to the https version.
2018-07-24 11:29:31 +09:00
Jędrek Domański
1e2650acbb Update documentation for #pluck method [ci skip] 2018-07-14 14:11:30 +02:00
Anthony Crumley
258670244d Added a lot of Oxford commas
[ci skip] A regular expression was used to find a lot of missing Oxford
commas and add them.  The regular expression was as follows.

", ([a-zA-Z0-9.\`:'\"]+ ){1,6}(or|and) "
2018-05-10 12:46:06 -05:00
bogdanvlviv
20bb26a428
Update "Active Record Query Interface" guide [ci skip]
- Add missing `LIMIT 1` for some queries
  - Make some examples of query more readable
2017-12-04 01:18:59 +02:00
Aditya Kapoor
0efc132a81 fix the description for the select_all [ci skip] 2017-10-12 15:54:09 +05:30
hupfis
8f24923d7a Fix typo in 'find_in_batches' example 2017-09-26 13:28:46 +02:00
Ryuta Kamizono
4b3ee155f9 Remove trailing spaces [ci skip] 2017-08-27 22:29:56 +09:00
Yoshiyuki Hirano
bf48e90e69 Use https instead of http in guide [ci skip] 2017-08-23 09:39:45 +09:00
yuuji.yaginuma
b52849d421 Change http postgresql.org links to https [ci skip]
It seems that it accepts only HTTPS connections.
Ref: 7f77cbd996
2017-07-30 21:52:31 +09:00
Abraham Chan
3b308f3321 Fix hash conditions documentation [ci skip] 2017-06-22 14:10:17 +10:00
Jon Moss
980ac58a51 Grammar fixes
[ci skip]
2017-05-29 19:56:22 -04:00
Matthew Draper
a824c679f3 Merge pull request #29246 from nihemak/fix-docs-take-first
[ci skip]fix wrong variable name in docs
2017-05-27 12:46:08 +09:30
Makoto Nihei
7cceb729e6 [ci skip]fix wrong variable name in docs 2017-05-27 12:03:57 +09:00
Makoto Nihei
9980709c5a [ci skip]fix wrong variable name in docs 2017-05-27 11:52:18 +09:00
Krzysztof Maicher
af41b98577 Add ActiveRecord::Relation#or description to guides [ci skip] 2017-05-25 15:20:36 +02:00
Ross Kaffenberger
9aeba503c4 Add default_scope note to AR guide [ci skip]
Adds note to explain unexpected behavior described in issue #28561.
Developers may be surprised that the internal representation of similar
query conditions in Hash and Array formats in default_scope will yield 
different results for model initialization.
Link: https://github.com/rails/rails/issues/28561
2017-03-31 18:11:15 -04:00
bogdanvlviv
5a072ba317 Remove ability update locking_column value 2017-03-16 10:42:33 +02:00
Vijay Dev
12038f6505 Merge branch 'master' of github.com:rails/docrails 2017-03-04 19:35:25 +00:00
Vipul A M
c0f621ae63
Fix generated query in Retrieving specific data from multiple tables section [ci skip] 2017-03-04 11:44:25 +05:30
Shay
069e33de66 fixed suspected typo in sample sql query 2017-03-02 20:55:30 +02:00
bogdanvlviv
25eed41c49 Update guides/source/active_record_querying.md
Add info about updating locking column value

Follow #26050 and #26871

[ci skip]
2016-11-10 20:42:23 +02:00
Jeremy Wilmot
7d0e73bc01 Remove dup distinct from AR query list [ci skip] 2016-09-30 15:12:16 -07:00
Andrey Molchanov
e1252e073a [ci skip] Fixed commas according to Oxford comma in rdoc and guides 2016-09-17 22:36:13 +03:00
Waitaya Krongapiradee
831f1b67b7 Fix table name typos [ci skip] 2016-09-08 16:41:16 +07:00
Danila Ermakov
3b7642a328 Change form of table name to plural in query example 2016-08-22 15:24:19 +03:00
Scott Antipa
f3626c38fc Update docs for query interface to not declare that all methods return instance of ActiveRecord::Relation 2016-08-21 11:17:37 -07:00
Vipul A M
0ee88bf1e7
Document know limitation about using references in conjunction with eager loading causing it to ignore custom select clauses.
[ci skip]

Fixes #24314
2016-08-09 14:14:53 +05:30
Chetna Sharma
a9dabd6939 [ci skip] Add documentation for error using select with order 2016-07-25 18:40:31 +05:30
Xavier Noria
07d3b588df finders guide: updates the section about batch processing [ci skip]
There are several edits here, but in particular it updates the
guide to reflect 451437c.
2016-07-14 09:40:31 +02:00
Junya Ogura
3c557cb333 Use #distinct instead of #uniq in the guides [ci skip] (#25098)
* #uniq will be deprecated, see: rails/rails@adfab2d
2016-05-21 11:06:34 -03:00
Tom Copeland
e1a31f51f4 Add SQL examples for equality and NOT [ci skip] 2016-04-21 17:19:45 -04:00
iangilfillan
48ef9408bc MariaDB Documentation 2016-04-14 14:06:29 +02:00
Laura Murphy-Clarkin
2657ec8973 Correct typos in "Active Record Query Interface" guide 2016-03-25 12:27:06 +00:00