[DOCS] Improve Documentation for ActiveRecord's order Method [ci-skip]#43018
Conversation
74dedc8 to
4ce1cb9
Compare
jonathanhefner
left a comment
There was a problem hiding this comment.
Thank you for working on this! 😃
There was a problem hiding this comment.
| # column names and simple function(column_name) expressions with optional | |
| # ASC/DESC modifiers are allowed. | |
| # column names and simple <code>function(column_name)</code> expressions | |
| # with optional +ASC+/+DESC+ modifiers are allowed. |
Also, what do you think about moving this paragraph up above the code examples?
There was a problem hiding this comment.
I thought this location transitioned nicely to Arel, and meant they had an understanding of what string values passed to order looked like, before adding the complication of when to use Arel, but I'm fine with moving it up to the first description.
6dcd2b8 to
8807b93
Compare
|
Updated to reflect all code review comments, and rebased to drop the commit "fix spelling of management in the changelog", because main is now fixed. |
jonathanhefner
left a comment
There was a problem hiding this comment.
One more thing. Then, when you are happy with the changes, would you mind squashing the commits?
There was a problem hiding this comment.
Sorry, this is my fault -- this needs to be
| # Applies an +ORDER BY+ clause to a query. | |
| # Applies an <code>ORDER BY</code> clause to a query. |
Because of the space:
> require "rdoc"
> RDoc::Markup::ToHtml.new(RDoc::Options.new).convert("+ORDER BY+ vs +ORDERBY+")
=> "\n<p>+ORDER BY+ vs <code>ORDERBY</code></p>\n"There was a problem hiding this comment.
Looking at some similar methods in this file, I'm not sure we should use ORDER BY here.
None of the other examples are using SQL in the description.
It also seems we use mostly relation instead of query.
This makes sense I guess, because a relation is returned.
reverse_order
https://github.com/rails/rails/blob/8807b93841ddd1a7fa2b2f44f02e1f690f3d9cc9/activerecord/lib/active_record/relation/query_methods.rb#L1151
reorder
https://github.com/rails/rails/blob/8807b93841ddd1a7fa2b2f44f02e1f690f3d9cc9/activerecord/lib/active_record/relation/query_methods.rb#L440
limit
https://github.com/rails/rails/blob/8807b93841ddd1a7fa2b2f44f02e1f690f3d9cc9/activerecord/lib/active_record/relation/query_methods.rb#L876
Where
https://github.com/rails/rails/blob/8807b93841ddd1a7fa2b2f44f02e1f690f3d9cc9/activerecord/lib/active_record/relation/query_methods.rb#L590-L591
Any objections if we change it to:
| # Applies an +ORDER BY+ clause to a query. | |
| # Applies an order clause to the relation. |
Or maybe, since multiple orders can be added:
| # Applies an +ORDER BY+ clause to a query. | |
| # Adds an order clause to the relation. |
Sorry for the bikeshed 🙇
There was a problem hiding this comment.
Looking at some similar methods in this file, I'm not sure we should use
ORDER BYhere.
None of the other examples are using SQL in the description.
There are a few that do:
rails/activerecord/lib/active_record/relation/query_methods.rb
Lines 20 to 21 in 4b4895e
rails/activerecord/lib/active_record/relation/query_methods.rb
Lines 258 to 259 in 4b4895e
rails/activerecord/lib/active_record/relation/query_methods.rb
Lines 390 to 391 in 4b4895e
rails/activerecord/lib/active_record/relation/query_methods.rb
Lines 830 to 831 in 4b4895e
That said, I don't have a strong preference. 😄
There was a problem hiding this comment.
I think including the ORDER BY provides more information than just saying order but I'm 50/50 on query vs relation, so I'll replace it with relation next time I'm at my computer.
There was a problem hiding this comment.
If we are sticking with the ORDER BY I guess it makes sense to also stick with query 🙂 .
4514ff2 to
a736b54
Compare
|
Squashed! |
|
Thanks @ChaelCodes ! This looks ready to go for me.. 🚢 🙌 |
8ae52a2 to
1d9841c
Compare
|
@p8 squashed and building. Sorry for the short message, it's early here. |
|
@ChaelCodes no worries 😄 . Thanks for the quick replies! |
Co-authored-by: Petrik de Heus <petrik@deheus.net> Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
1d9841c to
d6a38d2
Compare
|
Ack, I noticed Thank you again, @ChaelCodes! And thank you, @p8, for reviewing! |
Summary
Added documentation around the
ordermethod and what the acceptable parameters are. Strings have some interesting functionality where they raise an error if anything more complicated than a column name or function wrapping a column are passed. This wasn't documented, so let's fix that!Other Information