aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/querying.rb
Commit message (Collapse)AuthorAgeFilesLines
* Place class level `update`, `destroy`, and `delete` in ↵Ryuta Kamizono2017-09-181-1/+1
| | | | | | | | | | `Persistence::ClassMethods` The docs are obviously for class level `update`, `destroy`, and `delete`. It should be placed in `Persistence::ClassMethods` rather than `Relation`. And also, these methods are not dependent on relation. So it is not needed to delegate to `all` (plus, `klass.find` is faster than `relation.find`).
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add missing `delegate :extending, to: :all`Ryuta Kamizono2017-06-011-1/+1
|
* uniq was deprecated and removed alreadyRafael Mendonça França2017-03-171-1/+1
| | | | | This was causing an infinity loop since it was delegating to `all` and all delegating back to this module.
* Ensure that inverse associations are set before running callbacksSean Griffin2016-08-311-2/+2
| | | | | | | | | | | | | | | | | If a parent association was accessed in an `after_find` or `after_initialize` callback, it would always end up loading the association, and then immediately overwriting the association we just loaded. If this occurred in a way that the parent's `current_scope` was set to eager load the child, this would result in an infinite loop and eventually overflow the stack. For records that are created with `.new`, we have a mechanism to perform an action before the callbacks are run. I've introduced the same code path for records created with `instantiate`, and updated all code which sets inverse instances on newly loaded associations to use this block instead. Fixes #26320.
* Deprecate `sanitize_conditions`. Use `sanitize_sql` insteadRyuta Kamizono2016-08-181-2/+1
| | | | Because `sanitize_conditions` protected method is only used in one place.
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix the calling `merge` method at first in a scopesuginoy2016-07-191-1/+1
| | | | | | | | | | | | Changing the order of method chaining `merge` and other query method such as `joins` should produce the same result. ```ruby class Topic < ApplicationRecord scope :safe_chaininig, -> { joins(:comments).merge(Comment.newest) } scope :unsafe_chaininig, -> { merge(Comment.newest).joins(:comments) } #=> NoMethodError end ```
* Do not delegate `AR::Base#empty?` to `all`Sean Griffin2016-05-021-1/+1
| | | | | | | | | | Unlike `one?` and `none?`, `empty?` has interactions with methods outside of enumerable. It also doesn't fit in the same vein. `Topic.any?` makes sense. `Topic.empty?` does not, as `Topic` is not a container. Fixes #24808 Close #24812
* Delegate some additional methods in querying.rbKenta2016-03-301-1/+1
|
* Ensure prepared statement caching still occurs with Adequate RecordSean Griffin2016-02-111-2/+2
| | | | | | | | | | | | | In Rails 5, we're much more restrictive about when we do or don't cache a prepared statement. In particular, we never cache when we are sending an IN statement or a SQL string literal However, in the case of Adequate Record, we are *always* sending a raw SQL string, and we *always* want to cache the result. Fixes #23507 /cc @tgxworld
* rename to 'second_to_last' and 'third_to_last'Brian Christian2016-02-101-1/+1
|
* allow Array.penultimate and Array.antepenultiate access methodsBrian Christian2016-02-091-1/+1
|
* Alias left_joins to left_outer_joinsTakashi Kokubun2015-10-311-1/+1
|
* Merge pull request #12071 from Crunch09/outer_joinsSean Griffin2015-10-301-1/+1
|\ | | | | | | added ActiveRecord::Relation#outer_joins
| * added ActiveRecord::Relation#left_outer_joinsFlorian Thomas2015-05-191-1/+1
| | | | | | | | | | | | Example: User.left_outer_joins(:posts) => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" = "users"."id"
* | Add ActiveRecord::Relation#in_batchesSina Siadat2015-08-071-1/+1
|/ | | | | | | | | | | | | | | | | `in_batches` yields Relation objects if a block is given, otherwise it returns an instance of `BatchEnumerator`. The existing `find_each` and `find_in_batches` methods work with batches of records. The new API allows working with relation batches as well. Examples: Person.in_batches.each_record(&:party_all_night!) Person.in_batches.update_all(awesome: true) Person.in_batches.delete_all Person.in_batches.map do |relation| relation.delete_all sleep 10 # Throttles the delete queries end
* Added #or to ActiveRecord::RelationMatthew Draper2015-01-281-1/+1
| | | | | | | Post.where('id = 1').or(Post.where('id = 2')) # => SELECT * FROM posts WHERE (id = 1) OR (id = 2) [Matthew Draper & Gael Muller]
* Fix doc formatting for `count_by_sql`claudiob2015-01-011-3/+4
| | | | | | | | | | | | Before: ![before](https://cloud.githubusercontent.com/assets/10076/5592809/25ce08e8-9199-11e4-9dfe-5baa8bd6b658.png) After: ![after](https://cloud.githubusercontent.com/assets/10076/5592810/25ceef9c-9199-11e4-88f4-d286203d7f6f.png) [ci skip]
* Revert "Improve performance of AR object instantiation"Sean Griffin2014-11-141-1/+1
| | | | | | | | | | This reverts commit 8fee923888192a658d8823b31e77ed0683dfd665. Conflicts: activerecord/lib/active_record/attribute_set/builder.rb This solution sucks, and is hard to actually apply across the board. Going to try other solutions
* Improve performance of AR object instantiationSean Griffin2014-11-051-1/+1
| | | | | | | We introduced a performance hit by adding an additional iteration through a model's attributes on creation. We don't actually need the values from `Result` to be a hash, we can separate the columns and values and zip them up ourself during the iteration that we have to do.
* measure record instantiation time in AS::NotificationsAaron Patterson2014-10-131-1/+10
| | | | | emit an event when we instantiate AR objects so we can see how many records were instantiated and how long it took
* some object allocation reduction for new AR objectsAaron Patterson2014-09-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Benchmark: ```ruby require 'objspace' require 'active_record' ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:" ActiveRecord::Base.connection.instance_eval do create_table(:articles) { |t| t.string :name } end class Article < ActiveRecord::Base; end a = Article.create name: "foo" a = Article.find a.id N = 10 ObjectSpace::AllocationTracer.trace do N.times { Article.find a.id } end ObjectSpace::AllocationTracer.allocated_count_table table.sort_by { |_,x| x }.each do |k,v| p k => (v / N) end ```
* Remove old deprecation warningSean Griffin2014-06-221-8/+1
| | | | | This has been around for a couple of versions now, a `NoMethodError` should suffice at this point.
* No need to decorate columns twiceSean Griffin2014-06-101-1/+1
| | | | | | | We never want result types to override column types, and `decorate_columns` can only affect column types. No need to go through the decoration multiple times, we can just exclude the column types from the result types instead.
* Result sets never override a model's column typeSean Griffin2014-05-291-1/+1
| | | | | | | | | | | | MySQL and PostgreSQL provide a column type override in order to properly type cast computed columns included in a result set. This should never override the known types of full fledged columns. In addition to messing up computed properties, this would have led to inconsistent behavior between a record created with `new`, and a record created with `last` on the mysql adapter in the following cases: - `tinyint(1)` with `emulate_booleans` set to `false` - `text`, `string`, `binary`, and `decimal` columns
* Ensure #second acts like #first AR finderJason Meller2014-01-201-0/+1
| | | | | | | | | | | | This commit bring the famous ordinal Array instance methods defined in ActiveSupport into ActiveRecord as fully-fledged finders. These finders ensure a default ascending order of the table's primary key, and utilize the OFFSET SQL verb to locate the user's desired record. If an offset is defined in the query, calling #second adds to the offset to get the actual desired record. Fixes #13743.
* Delegate #rewhere to all on the class like all other relation methodsDavid Heinemeier Hansson2013-11-021-1/+1
|
* Moving the `pluck` and `ids` methods to their own delegate line.wangjohn2013-06-251-8/+9
| | | | | | | | These two methods aren't really statistical helper methods and don't really belong in any other group which is being delegated for querying, so I'm moving them to their own group of methods. I've also changed the `:to => :all` hash syntax to `to: :all`.
* improved doc for ActiveRecord#find_by_sql method (Refs #10599) [ci skip]Anton Kalyaev2013-05-141-3/+4
|
* Delegate #unscope query methodCarlos Antonio da Silva2013-04-281-1/+1
|
* rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-151-1/+1
| | | | | | | | The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
* remove AR auto-explain (config.auto_explain_threshold_in_seconds)Yves Senn2013-02-241-14/+10
| | | | | | | | | | We discussed that the auto explain feature is rarely used. This PR removes only the automatic explain. You can still display the explain output for any given relation using `ActiveRecord::Relation#explain`. As a side-effect this should also fix the connection problem during asset compilation (#9385). The auto explain initializer in the `ActiveRecord::Railtie` forced a connection.
* Refactor to use each_key, remove extra spacesCarlos Antonio da Silva2013-01-281-1/+0
|
* Cleans and removes 'Examples' tag [ci skip]Alvaro Pereyra2012-12-011-5/+2
|
* Add Relation#find_or_create_by and friendsJon Leighton2012-10-191-0/+1
| | | | | | | This is similar to #first_or_create, but slightly different and a nicer API. See the CHANGELOG/docs in the commit. Fixes #7853
* Remove ActiveRecord::Base.to_aJon Leighton2012-08-031-1/+1
| | | | | On reflection, it seems like a bit of a weird method to have on ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
* load active_support/deprecation in active_support/railsXavier Noria2012-08-021-1/+0
|
* load active_support/core_ext/module/delegation in active_support/railsXavier Noria2012-08-021-1/+0
|
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-7/+7
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* Log query plan when we use count_by_sql method.kennyj2012-07-181-2/+4
|
* Introducing `take` as a replacement to the old behavior of `first`Marcelo Silveira2012-05-021-1/+1
|
* Fix PR #6091Andrew White2012-04-301-1/+1
| | | | | | 1. ActiveRecord::Base is not ActiveRecord::Relation 2. The order of records from an SQL query is uncertain without an ORDER clause 3. Run your own tests when submitting a pull request
* Add Relation#find_by and Relation#find_by!Jon Leighton2012-03-301-0/+1
|
* column types are passed from the result set to the instantiated AR objectAaron Patterson2012-02-071-1/+10
|
* Merge pull request #4805 from xuanxu/none_and_null_object_patternJon Leighton2012-01-311-1/+1
|\ | | | | Added `none` query method to return zero records.
| * Added `none` query method to return zero records.Juanjo Bazán2012-01-311-1/+1
| | | | | | And added NullRelation class implementing the null object pattern for the `Relation` class.
* | always return the result set from select_allAaron Patterson2012-01-311-1/+1
| |