aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix code formatting for QueryMethods#selectRobin Dupret2017-07-161-2/+3
| | | | [ci skip]
* Fix `create_with` using both string and symbolRyuta Kamizono2017-07-161-1/+1
| | | | | | | This is related with #27680. Since `where_values_hash` keys constructed by `where` are string, so we need `stringify_keys` to `create_with_value` before merging it.
* Skip query cache for in_batches and friendsEugene Kenny2017-07-061-0/+5
| | | | | | | | | | | The `find_each`, `find_in_batches` and `in_batches` APIs usually operate on large numbers of records, where it's preferable not to load them all into memory at once. If the query cache is enabled, it will hold onto the query results until the end of the execution context (request/job), which means the memory used is still proportional to the total number of records. These queries are typically not repeated, so the query cache isn't desirable here.
* [Active Record] require => require_relativeAkira Matsuda2017-07-011-4/+4
|
* Fix extracting `references` via `order_values` to respect quotingRyuta Kamizono2017-06-261-1/+1
|
* Don't require 'unscope' to be the same for both sides of a 'or' relation.Dan Sherson2017-06-151-1/+1
|
* Make `VALID_DIRECTIONS` to `Set`Ryuta Kamizono2017-05-201-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```ruby require "benchmark/ips" require "set" array = [:asc, :desc, :ASC, :DESC, "asc", "desc", "ASC", "DESC"] set = array.to_set item = "DESC" Benchmark.ips do |x| x.report "array" do array.include?(item) end x.report "set" do set.include?(item) end end ``` ``` % ruby array_vs_set.rb Warming up -------------------------------------- array 188.441k i/100ms set 229.531k i/100ms Calculating ------------------------------------- array 3.508M (± 9.0%) i/s - 17.525M in 5.043058s set 5.134M (± 7.6%) i/s - 25.707M in 5.038921s ```
* Fix ambigious error message of select query methodMehmet Emin INAC2017-05-081-1/+1
|
* Allow order to be given expressions as hash keysEugene Kenny2017-02-271-1/+6
| | | | | | | | | | | | | When `order` is given a hash, the keys are currently assumed to be attribute names and are quoted as such in the query, which makes it impossible to pass an expression instead: Post.order("LENGTH(title)" => :asc).last # SELECT `posts`.* FROM `posts` ORDER BY `posts`.`LENGTH(title)` DESC LIMIT 1 If the key is an `Arel::Nodes::SqlLiteral`, we now use it directly in the query. This provides a way to build a relation with a complex order clause that can still be reversed with `reverse_order` or `last`.
* `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-051-1/+1
| | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* Remove unneeded requires at active recordRafael Mendonça França2017-01-031-1/+0
|
* Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`Ryuta Kamizono2016-12-301-4/+0
|
* Remove deprecated support to passing arguments to `#select` when a block is ↵Rafael Mendonça França2016-12-291-3/+1
| | | | provided.
* 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
|