aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #11650 from prathamesh-sonpatki/renameRafael Mendonça França2014-04-041-1/+1
|\ | | | | | | Renamed private methods _create_record and _update_record
| * [Active Record] Renamed private methods create_record and update_recordPrathamesh Sonpatki2014-02-201-1/+1
| | | | | | | | | | | | This is to ensure that they are not accidentally called by the app code. They are renamed to _create_record and _update_record respectively. Closes #11645
* | `includes` uses SQL parsing when String joins are involved.Yves Senn2014-02-281-1/+10
|/ | | | | | | | | | | | | | This is a partial revert of 22b3481ba2aa55fad1f9a5db94072312b345fb55. The current implementation of `references_eager_loaded_tables?` needs to know every table involved in the query. With the current API this is not possible without SQL parsing. While a2dab46cae35a06fd5c5500037177492a047c252 deprecated SQL parsing for `includes`. It did not issue deprecation warnings when String joins are involved. This resulted in a breaking change after the deprecated behavior was removed (22b3481ba2aa55fad1f9a5db94072312b345fb55). We will need to rethink the usage of `includes`, `preload` and `eager_load` but for now, this brings back the old *working* behavior.
* Remove duplicate mergekei2014-01-221-1/+0
|
* Remove missed usage of @first variableCarlos Antonio da Silva2014-01-211-1/+1
| | | | | | | | With the introduction of `#second` method and friends, we added an offsets hash which replaced the @first variable, so removing it from the reset method to avoid creating an unused variable now. Introduced in bc625080308e4853ae3036f2ad74fe3826e463ef.
* Remove unneded argumentRafael Mendonça França2014-01-201-2/+2
| | | | This variable is internal and should not be exposed to end users
* Ensure #second acts like #first AR finderJason Meller2014-01-201-1/+3
| | | | | | | | | | | | 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.
* Fix ActiveRecord::Relation#unscopeJon Leighton2013-11-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm pretty confused about the addition of this method. The documentation says that it was intended to allow the removal of values from the default scope (in contrast to #except). However it behaves exactly the same as except: https://gist.github.com/jonleighton/7537008 (other than having a slightly enhanced syntax). The removal of the default scope is allowed by 94924dc32baf78f13e289172534c2e71c9c8cade, which was not a change we could make until 4.1 due to the need to deprecate things. However after that change #unscope still gives us nothing that #except doesn't already give us. However there *is* a desire to be able to unscope stuff in a way that persists across merges, which would allow associations to be defined which unscope stuff from the default scope of the associated model. E.g. has_many :comments, -> { unscope where: :trashed } So that's what this change implements. I've also corrected the documentation. I removed the guide references to #except as I think unscope really supercedes #except now. While we're here, there's also a potential desire to be able to write this: has_many :comments, -> { unscoped } However, it doesn't make sense and would not be straightforward to implement. While with #unscope we're specifying exactly what we want to be removed from the relation, with "unscoped" we're just saying that we want it to not have some things which were added earlier on by the default scope. However in the case of an association, we surely don't want *all* conditions to be removed, otherwise the above would just become "SELECT * FROM comments" with no foreign key constraint. To make the above work, we'd have to somehow tag the relation values which get added when evaluating the default scope in order to differentiate them from other relation values. Which is way too much complexity and therefore not worth it when most use cases can be satisfied with unscope. Closes #10643, #11061.
* pass the pk to compile_updateAaron Patterson2013-11-161-1/+1
|
* Fix test name [ci skip]Carlos Antonio da Silva2013-11-141-2/+0
|
* Fix that eager loading of polymorphic associations did not work with ↵David Heinemeier Hansson2013-11-141-1/+9
| | | | association empty?/any? predicates any more (there is still a problem when select is applied to a relation, or if you try association#exists? -- but its easier to work around)
* Merge branch 'master' into joindepAaron Patterson2013-10-211-2/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (23 commits) Escape the parentheses in the default function regexp Update docs on Tilt::Template in Asset Pipeline guide Fix loading a sql structure file on postgres when the file's path has whitespace in it remove trailing whitespace added with b057765 [ci skip]. Allow unscope to work with `where.not` Raise an exception when model without primary key calls .find_with_ids Process sub-query relation's binding values Instrument the generation of Action Mailer messages Remove extra variable creation and merge. In Relation#empty? use #exists? instead of #count. [ci skip] avoid deprecation warning in sample code Convert Fixnum into String the port number in MySQL Fix some indentation on autosave association Make define_non_cyclic_method simpler Add Sass gobbling info to asset pipeline docs Ensure the state is clean after one failure Fix typo in form_helper.rb add a new local variable to track if digests are being stored, to ensure the cleanup works correctly [ci skip] Fix number of methods added by association. update digestor code based on review ...
| * In Relation#empty? use #exists? instead of #count.Szymon Nowak2013-10-191-2/+1
| |
* | eliminate duplicate code from to_sqlAaron Patterson2013-10-131-3/+1
| | | | | | | | I don't really like passing the block, but this seems easiest for now
* | push up `select` exclusionAaron Patterson2013-10-131-1/+2
|/
* reuse the same preloader object for each associationAaron Patterson2013-09-231-2/+2
|
* remove state from the preloaderAaron Patterson2013-09-231-1/+2
|
* refactor to_sql so it does not depend on the to_sql implementation ofAaron Patterson2013-07-081-4/+11
| | | | the connection
* fix to_sql output on eager loaded relationsAaron Patterson2013-07-021-1/+9
|
* remove deprecated implicit join references.Yves Senn2013-06-291-37/+2
|
* Simplify/fix implementation of default scopesJon Leighton2013-06-281-35/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation was necessary in order to support stuff like: class Post < ActiveRecord::Base default_scope where(published: true) scope :ordered, order("created_at") end If we didn't evaluate the default scope at the last possible moment before sending the SQL to the database, it would become impossible to do: Post.unscoped.ordered This is because the default scope would already be bound up in the "ordered" scope, and therefore wouldn't be removed by the "Post.unscoped" part. In 4.0, we have deprecated all "eager" forms of scopes. So now you must write: class Post < ActiveRecord::Base default_scope { where(published: true) } scope :ordered, -> { order("created_at") } end This prevents the default scope getting bound up inside the "ordered" scope, which means we can now have a simpler/better/more natural implementation of default scoping. A knock on effect is that some things that didn't work properly now do. For example it was previously impossible to use #except to remove a part of the default scope, since the default scope was evaluated after the call to #except.
* cleanup whitespace in relation.rbYves Senn2013-06-091-1/+1
|
* Revert "Merge pull request #10539 from davidcelis/ar-sql-improvements"Jon Leighton2013-06-071-1/+5
| | | | | | | | | This reverts commit 257fa6897d9c85da16b7c9fcb4ae3008198d320e, reversing changes made to 94725b81f5588e4b0f43222c4f142c3135941b4b. The build failed https://travis-ci.org/rails/rails/builds/7883546
* ActiveRecord::Relation#blank? should `LIMIT 1`David Celis2013-06-071-5/+1
| | | | | | | | | | | | | | | This is an SQL improvement to ActiveRecord::Relation#blank?. Currently, it calls `to_a` on the Relation, which loads all records in the association, and calls `blank?` on the loaded Array. There are other ways, however, to check the emptiness of an association that are far more performant. `#empty?`, `#exists?` and `#any?` all attach a `LIMIT 1` to the SQL query before firing it off, which is a nice query improvement. `#blank?` should do the same! Bonus performance improvements will also happen for `#present?`, which merely calls the negation of `#blank?` Signed-off-by: David Celis <me@davidcel.is>
* revises the documentation of ActiveRecord::Relation#find_or_create_by [ci skip]Xavier Noria2013-06-011-14/+38
| | | | | | | | | | | | | | * Inspect uses double quotes. * Inspect puts a hash as in #<User ...>. * Documents the return value, and makes explicit it can be an invalid record. * Documents the method is not atomic. * Documents a way to handle UNIQUE contraint violations in the event of a race condition. * Removes the "Examples" header according to our guidelines.
* `implicit_readonly` is being removed in favor of calling `readonly` explicitlyYves Senn2013-05-271-5/+1
|
* cleanup whitespace in `active_record/relation.rb`.Yves Senn2013-05-271-4/+4
|
* include bind values from the default scopeAaron Patterson2013-05-171-2/+4
|
* Move #proxy_association method to AssociationRelationJon Leighton2013-05-101-1/+1
|
* Added :nodoc: for private methodsNoemj2013-04-301-3/+3
|
* Moved update_record logic to relation.rbNoemj2013-04-301-11/+25
|
* Refactor CollectionProxy#scope to avoid calling #extend.James Golick2013-04-021-1/+1
|
* :uniq is still a valid relation option since it was only silentlyRafael Mendonça França2013-04-011-1/+1
| | | | | | | | deprecated Fixes activerecord-deprecated_finders build. https://travis-ci.org/rails/activerecord-deprecated_finders/builds/5964703
* entirelyby => 'entirely by'Neeraj Singh2013-03-271-1/+1
|
* Fixed typos in activerecordPrathamesh Sonpatki2013-03-271-1/+1
|
* make it possible to disable implicit join references.Yves Senn2013-03-151-2/+6
| | | | Closes #9712.
* rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-151-1/+7
| | | | | | | | 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 unused return value, because collecting_queries_for_explain isn't ↵kennyj2013-03-061-2/+1
| | | | public API.
* fix the sql that is generated from scopingNeeraj Singh2013-03-031-1/+2
|
* remove AR auto-explain (config.auto_explain_threshold_in_seconds)Yves Senn2013-02-241-11/+1
| | | | | | | | | | 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.
* Improve relation docs about to_sql and where_values_hashCarlos Antonio da Silva2013-01-191-4/+4
| | | | | | | | * User class instead of Users. * #where_values_hash does not change the value to downcase as the example was showing. [ci skip]
* Fix .update_all and .delete_all when using a condition on a joined tableDerek Kraan2013-01-111-2/+2
| | | | | | | | | in a default_scope. `Model.joins(...).where(condition_on_joined_table).update_all` / `delete_all` worked, but the same operation implemented with a default_scope generated a SQL error because ActiveRecord ignored the join but implemented the where condition anyways.
* Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-1/+1
|
* Remove observers and sweepersRafael Mendonça França2012-11-281-6/+3
| | | | | | | | They was extracted from a plugin. See https://github.com/rails/rails-observers [Rafael Mendonça França + Steve Klabnik]
* Move initialize_copy method around to let new method / build alias closerCarlos Antonio da Silva2012-11-241-8/+8
|
* 1.9 Syntax related changesAvnerCohen2012-11-101-1/+1
|
* Another batch of hash syntax changes to comment, this time around, I tried ↵AvnerCohen2012-10-231-5/+5
| | | | to keep 'output' messages untouched.
* nodoc the first_or_create methods and document alternativesJon Leighton2012-10-191-37/+18
|
* Add Relation#find_or_create_by and friendsJon Leighton2012-10-191-0/+26
| | | | | | | This is similar to #first_or_create, but slightly different and a nicer API. See the CHANGELOG/docs in the commit. Fixes #7853
* Move two hotspots to use Hash[] rather than Hash#dupAaron Patterson2012-10-151-3/+5
| | | | https://bugs.ruby-lang.org/issues/7166