aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove deprecated support to query using commas on LIMITRafael Mendonça França2016-12-291-19/+2
|
* Call `spawn` and bang method for `none`Ryuta Kamizono2016-11-141-1/+1
| | | | All query methods calls `spawn` and bang method, but only `none` is not.
* let Regexp#match? be globally availableXavier Noria2016-10-271-1/+0
| | | | | | Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation.
* Fix regression caused due to removal of select method from CollectionAssociationPrathamesh Sonpatki2016-10-221-1/+10
| | | | | | | | | | | | | | | | - CollectionAssociation#select was removed in https://github.com/rails/rails/pull/25989 in favor of QueryMethods#select but it caused a regression when passing arguments to select and a block. - This used to work earlier in Rails 4.2 and Rails 5. See gist https://gist.github.com/prathamesh-sonpatki/a7df922273473a77dfbc742a4be4b618. - This commit restores the behavior of Rails 4.2 and Rails 5.0.0 to allow passing arguments and block at the same time but also deprecates it. - Because, these arguments do not have any effect on the output of select when select is used with a block. - Updated documentation to remove the example passing arguments and block at the same time to `CollectionProxy#select`.
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-16/+16
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Fix Remaining Case-In-Assignment Statement FormattingAlex Kitchens2016-09-061-5/+6
| | | | | | | | | Recently, the Rails team made an effort to keep the source code consistent, using Ruboco (bb1ecdcc677bf6e68e0252505509c089619b5b90 and below). Some of the case statements were missed. This changes the case statements' formatting and is consistent with changes in 810dff7c9fa9b2a38eb1560ce0378d760529ee6b and db63406cb007ab3756d2a96d2e0b5d4e777f8231.
* Remove not used alias methodyui-knk2016-09-061-1/+0
| | | | | Bang methods of `AR::QueryMethods` are used only internally. We only use `left_outer_joins!`, so we can remove this alias.
* Add `Type.default_value` and use it everywhere for internalRyuta Kamizono2016-08-261-2/+2
| | | | For reduce instantiating `Type::Value`.
* Merge pull request #26182 from bogdan/remove-relation-metaprogrammingRafael França2016-08-231-76/+49
|\ | | | | Remove over meta programming in AR::Relation
| * Remove over meta programming in AR::RelationBogdan Gusiev2016-08-231-76/+49
| | | | | | | | | | | | | | | | | | | | Introduced low level methods #set_value and #get_value for setting query attributes: relation.set_value(:where, {id: 1}) relation.get_value(:includes) Used those internally when working with relation's attributes at the abstract level
* | Fix indentationRafael Mendonça França2016-08-171-3/+3
| |
* | Merge pull request #25987 from aquajach/masterRafael Mendonça França2016-08-171-1/+1
|\ \ | |/ |/| | | Fix does_not_support_reverse? to find sql functions with commas in nested brackets
| * check if order contains comma first in does_not_support_reverse?Jack Chen Songyong2016-07-291-1/+1
| |
| * have does_not_support_reverse? support sql functions with commas in nested ↵Jack2016-07-291-1/+1
| | | | | | | | brackets
* | code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | | | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-061-206/+206
| |
* | applies new string literal convention in activerecord/libXavier Noria2016-08-061-10/+10
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* adds missing requiresXavier Noria2016-07-241-0/+1
|
* systematic revision of =~ usage in ARXavier Noria2016-07-231-4/+4
| | | | | Where appropriatei, prefer the more concise Regexp#match?, String#include?, String#start_with?, or String#end_with?
* Fix `or` result SQL [ci skip]Ryuta Kamizono2016-06-111-1/+1
|
* Remove unused `association_for_table` private methodRyuta Kamizono2016-05-271-6/+0
| | | | `association_for_table` is unused since 50a8cdf.
* Allow the connection adapters to determine the order of bind paramsSean Griffin2016-05-061-4/+10
| | | | | | | | | | | | In 5.0 we use bind parameters for limit and offset, while in 4.2 we used the values directly. The code as it was written assumed that limit and offset worked as `LIMIT ? OFFSET ?`. Both Oracle and SQL Server have a different syntax, where the offset is stated before the limit. We delegate this behavior to the connection adapter so that these adapters are able to determine how the bind parameters are flattened based on what order their specification has the various clauses appear. Fixes #24775
* Show proper error message when a non-relation object is passed to ↵Prathamesh Sonpatki2016-02-171-0/+4
| | | | | | | | | | | | | | AR::Relation#or - Previously it used to show error message <"undefined method `limit_value' for {:title=>\"Rails\"}:Hash"> - Now it shows following error message. >> Post.where.not(name: 'DHH').or(name: 'Tenderlove') ArgumentError: You have passed Hash object to #or. Pass an ActiveRecord::Relation object instead. - Fixes #23714.
* Make ActiveRecord::Relation#last to reverse SQL orderBogdan Gusiev2016-02-131-0/+2
| | | | instead of loading the relation into memory
* Extract a Relation#arel_attributeMatthew Draper2016-02-041-4/+4
|
* Defer Arel attribute lookup to the model classMatthew Draper2016-02-041-7/+5
| | | | | This still isn't as separated as I'd like, but it at least moves most of the burden of alias mapping in one place.
* Introduce ActiveRecord::IrreversibleOrderErrorBogdan Gusiev2016-01-271-2/+16
| | | | | Raises when #reverse_order can not process SQL order instead of making invalid SQL before this patch
* Improve error message for #or when it is structurally incompatibleRafael Mendonça França2016-01-131-6/+8
| | | | | | | | When you are using scopes and you chaining these scopes it is hard to know which are the values that are incompatible. This way you can read the message and know for which values you need to look for. [Herminio Torres]
* activerecord: reuse immutable objectsTamir Duberstein2016-01-041-10/+12
|
* Improve example of #or to use different column values in the where clausesTim Sandberg2015-12-301-2/+2
|
* remove extra spaces from deprecation messageyuuji.yaginuma2015-12-151-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` # before DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes `String`s to be parsed as if they were in `Time.zone`, and `Time`s to be converted to `Time.zone`. To keep the old behavior, you must add the following to your initializer: config.active_record.time_zone_aware_types = [:datetime] To silence this deprecation warning, add the following: config.active_record.time_zone_aware_types << :time ``` ``` # after DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes `String`s to be parsed as if they were in `Time.zone`, and `Time`s to be converted to `Time.zone`. To keep the old behavior, you must add the following to your initializer: config.active_record.time_zone_aware_types = [:datetime] To silence this deprecation warning, add the following: config.active_record.time_zone_aware_types << :time ```
* Use a bind param for `LIMIT` and `OFFSET`Sean Griffin2015-12-141-4/+30
| | | | | | | | | | | | | | | We currently generate an unbounded number of prepared statements when `limit` or `offset` are called with a dynamic argument. This changes `LIMIT` and `OFFSET` to use bind params, eliminating the problem. `Type::Value#hash` needed to be implemented, as it turns out we busted the query cache if the type object used wasn't exactly the same object. This drops support for passing an `Arel::Nodes::SqlLiteral` to `limit`. Doing this relied on AR internals, and was never officially supported usage. Fixes #22250.
* Deprecate limit strings with commasSean Griffin2015-12-141-0/+6
| | | | | | | | | | Some backends allow `LIMIT 1,2` as a shorthand for `LIMIT 1 OFFSET 2`. Supporting this in Active Record massively complicates using bind parameters for limit and offset, and it's trivially easy to build an invalid SQL query by also calling `offset` on the same `Relation`. This is a niche syntax that is only supported by a few adapters, and can be trivially worked around by calling offset explicitly.
* Docs: ActiveRecord::QueryMethods#joinsJared Beck2015-11-251-2/+22
| | | | [ci skip]
* Update and fix forbidden attributes testsThomas Walpole2015-11-031-0/+4
| | | | Add AC::Parameters tests for WhereChain#not
* Define `sanitize_sql_for_order` for AR and use it inside `preprocess_order_args`yui-knk2015-11-021-5/+1
| | | | This commit follows up of 6a6dbb4c51fb0c58ba1a810eaa552774167b758a.
* Alias left_joins to left_outer_joinsTakashi Kokubun2015-10-311-0/+2
|
* Merge pull request #12071 from Crunch09/outer_joinsSean Griffin2015-10-301-1/+39
|\ | | | | | | added ActiveRecord::Relation#outer_joins
| * added ActiveRecord::Relation#left_outer_joinsFlorian Thomas2015-05-191-1/+39
| | | | | | | | | | | | Example: User.left_outer_joins(:posts) => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" = "users"."id"
* | Merge pull request #13008 from ktheory/sanitize_orderSean Griffin2015-10-291-0/+7
|\ \ | | | | | | | | | Support SQL sanitization in AR::QueryMethods#order
| * | Support SQL sanitization in AR::QueryMethods#orderAaron Suggs2013-11-221-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for sanitizing arrays in SQL ORDER clauses. This is useful when using MySQL `ORDER BY FIELD()` to return records in a predetermined way. ```ruby Tag.order(['field(id, ?', [1,3,2]].to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, 1,3,2) ``` Prior to this, developers must be careful to sanitize `#order` arguments themselves.
* | | Do not omit parentheses [ci skip]Ryuta Kamizono2015-10-251-1/+1
| | |
* | | Green version of moving the handling of supported arguments to `where`yui-knk2015-10-181-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | This commit follow up of 4d8f62d. The difference from 4d8f62d are below: * Change `WhereClauseFactory` to accept `Arel::Nodes::Node` * Change test cases of `relation_test.rb`
* | | Revert "Move the handling of supported arguments to `where`"Rafael Mendonça França2015-10-171-0/+2
| | | | | | | | | | | | | | | | | | This reverts commit 4d8f62dcfa0a5157b3facbd71f75fc6639636347. Reason: This broke the build. Please recommit again when it is green.
* | | Move the handling of supported arguments to `where`Sean Griffin2015-10-161-2/+0
| | | | | | | | | | | | | | | | | | `WhereClauseFactory` handles all other branches based on argument types, so the code fits more naturally here, and it's just where the responsibility belongs.
* | | `where` raises ArgumentError on unsupported types.Jake Worth2015-10-161-0/+2
| | | | | | | | | | | | [#20473]
* | | applies new doc guidelines to Active Record.Yves Senn2015-10-141-17/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* | | `private def` breaks RDoc. Move meathod to preserve the docs.Yves Senn2015-10-131-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The rdoc parser seems to trip on the `private def` construct. Public methods following a method defined with `private def` are not visible inside the module docs but are appended to the top-most module. For example the method `ActiveRecord::QueryMethods#distinct` was listed under `ActiveRecord#distinct`. /cc @sgrif
* | | docs, recognize code examples as Ruby in `Relation::QueryMethods` [ci skip]Yves Senn2015-10-131-33/+37
| | | | | | | | | | | | | | | | | | | | | | | | Also unify the format of code example output. Only use `# =>` if the actual return value is described. Otherwise simply use `#`. Conflicts: activerecord/lib/active_record/relation/query_methods.rb
* | | Remove unused requireakihiro172015-10-081-1/+0
| | | | | | | | | | | | `require 'active_support/core_ext/string/filters'` was added in b3bfa36. However, it is no longer needed from 3ae981814.