aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
...
| * don't bother with an offset if the offset is zeroAaron Patterson2014-04-121-6/+9
| | | | | | | | | | we're guaranteed to pass a numeric value for offset, so if it's zero, just don't add an offset to the query
| * only add the offset and index when we need toAaron Patterson2014-04-121-8/+9
| |
| * remove branching logic from calls to find_nthAaron Patterson2014-04-121-6/+10
| |
* | Merge branch 'master' into adequaterecordAaron Patterson2014-03-131-2/+13
|\| | | | | | | | | | | * master: passing an instance of an AR object to `find` is deprecated passing an ActiveRecord object to `exists?` is deprecated.
| * passing an instance of an AR object to `find` is deprecatedAaron Patterson2014-03-131-1/+5
| | | | | | | | please pass the id of the AR object by calling `.id` on the model first.
| * passing an ActiveRecord object to `exists?` is deprecated.Aaron Patterson2014-03-131-1/+8
| | | | | | | | | | Pass the id of the object to the method by calling `.id` on the AR object.
* | `where` automatically uses bind values nowAaron Patterson2014-03-131-5/+2
| |
* | Merge branch 'master' into adequaterecordAaron Patterson2014-03-131-1/+6
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (108 commits) make tests pass on Ruby 2.2 Use Sqlite3 adapter in examples use the body proxy to freeze headers just ask the response for the commit status, we do not need to ask the jar only write the jar if the response isn't committed Fix a grammatical error in the i18n guide [ci skip] use method_defined? to check whether or not a method is defined Enhance docs for update_attribute [ci-skip] Change usec to 0 on tests that compare seconds Unit test for mysql quote time usec Changelog entry for mysql56 microseconds Test microsecond on mysql 5.6 MySQL 5.6 and later supports microsecond precision in datetime. [ci skip] Add documentation for original_fullpath. Remove mocking on save, when not necessary comment why we are modifying global state. [ci skip] `change_table` supports `citext`. Follow up to #12523. Removed unnecessary command "application" register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester] Fixes STI when 2+ levels deep. ...
| * Make exists? use bound values.Martin Schürrer2014-03-041-1/+6
| | | | | | | | | | | | | | | | | | | | | | When we build a query with an inline value that is a numeric (e.g. because it's out of range for an int4) PostgreSQL doesn't use an index on the column, since it's now comparing numerics and not int4s. This leads to a _very_ slow query. When we use bound parameters instead of inline values PostgreSQL raises numeric_value_out_of_range since no automatic coercion happens.
* | Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-11/+99
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (311 commits) Add a missing changelog entry for #13981 and #14035 Revert "Fixed plugin_generator test" implements new option :month_format_string for date select helpers [Closes #13618] add factory methods for empty alias trackers guarantee a list in the alias tracker so we can remove a conditional stop exposing table_joins make most parameters to the AliasTracker required make a singleton for AssociationScope pass the association and connection to the scope method pass the tracker down the stack and construct it in the scope method clean up add_constraints signature remove the reflection delegate remove klass delegator remove railties changes. fixes #14054 remove chain delegate remove scope_chain delegate Add verb to sanitization note fix path shown in mailer's templates updated Travis build status image url fix guide active_support_core_extensions. add Note to String#indent [ci skip] ... Conflicts: activerecord/lib/active_record/associations/join_dependency.rb activerecord/test/cases/associations/association_scope_test.rb
| * guarantee a list in the alias tracker so we can remove a conditionalAaron Patterson2014-02-141-1/+9
| |
| * Fix `ActiveRecord::RecordNotFound` error message with custom primary keyKuldeep Aggarwal2014-01-251-2/+2
| |
| * Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
| * Ensure #second acts like #first AR finderJason Meller2014-01-201-7/+87
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | adding bind values to the manager objectAaron Patterson2014-01-131-1/+2
|/
* doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip]Yves Senn2014-01-101-0/+1
| | | | Refs #13658
* Fix offset with last.Lauro Caetano2013-12-031-1/+1
| | | | Closes #7441
* document id prefixed String usage of `.find`. refs #12891 [ci skip]Yves Senn2013-11-151-5/+6
|
* Merge branch 'master' into joindepAaron Patterson2013-10-211-0/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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 ...
| * Raise an exception when model without primary key calls .find_with_idsShimpei Makimoto2013-10-211-0/+2
| |
| * Don't remove the select values to add they back againRafael Mendonça França2013-10-151-1/+1
| | | | | | | | | | Conflicts: activerecord/lib/active_record/relation/finder_methods.rb
* | Merge branch 'master' into joindepAaron Patterson2013-10-151-2/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (44 commits) grammar fix (reverted in e9a1ecd) Revert "fixed a doc bug in the CHANGELOG.md s/does no longer depend on/no longer depends on/" Add missed require making `enable_warnings` available Prepare generated Gemfile for Capistrano 3 Added --model-name option scaffold_controller_generator. read the association instead of sending we should have unique sponsorable ids in the fixtures at least simplify populating the ordering hash the preloader for the RHS has all the preloaded records, so ask it only calculate offset index once. #12537 Remove size alias for length validation Fix `singleton_class?` Minor Refactoring to `NumberHelper#number_to_human` `$SAFE = 4;` has been removed with Ruby 2.1 scope_chain should not be mutated for other reflections Remove `default_primary_key_type` and extract contains of `native_database_types` to a constant since they aren't conditional now in SQLite3Adapter. Makes it more like other adapters. cleanup changelog entry format. [ci skip] Extract a function to determine if the default value is a function Push default_function to superclass to avoid method check Dump the default function when the primary key is uuid ... Conflicts: activerecord/lib/active_record/relation/finder_methods.rb
| * Merge pull request #11791 from versioncontrol/includes_with_persistent_selectRafael Mendonça França2013-10-121-1/+1
| |\ | | | | | | Includes with persistent select, fixes #11773
| | * Fixes #11773 when using includes combined with select, the select statement ↵Edo Balvers2013-10-081-1/+1
| | | | | | | | | | | | was overwritten.
* | | keep a cache on the alias objectAaron Patterson2013-10-141-1/+1
| | |
* | | store aliases in a better structureAaron Patterson2013-10-141-1/+3
| | |
* | | eliminate single use methodAaron Patterson2013-10-131-6/+3
| | |
* | | eliminate duplicate code from to_sqlAaron Patterson2013-10-131-4/+8
| | | | | | | | | | | | I don't really like passing the block, but this seems easiest for now
* | | calling construct_relation_for_association_find is no longer necessaryAaron Patterson2013-10-131-1/+1
| | |
* | | push up `select` exclusionAaron Patterson2013-10-131-3/+4
| | |
* | | JoinDependency will take care of making things uniqueAaron Patterson2013-10-131-1/+1
|/ /
* / stuff the join dependency object in the "anything goes" hash.Aaron Patterson2013-10-101-1/+1
|/
* let AR::FinderMethods#exists? return singletons in all cases [closes #11592]Xavier Noria2013-08-191-7/+7
| | | | | | | | | | | | | | | | | | | | | This fixes a regression. The documentation said in its introduction paragraph that the method returns truthy/falsy, but then below it was said that if there were no arguments you'd get `true` or `false`. Also when the argument is exactly `false` a singleton is documented to be returned. The method was not returning the singletons so it didn't conform to those special cases. The best solution here seems to be to just return singletons in all cases. This solution is backwards compatible. Also, the contract has been revised because it has no sense that the predicate varies that way depending on the input. I bet the previous contract was just an accident, not something mixed on purpose. Conflicts: activerecord/lib/active_record/relation/finder_methods.rb activerecord/test/cases/finder_test.rb
* fix visibility of the relation construction methodsAaron Patterson2013-07-091-5/+7
|
* pass arel to select_all rather than depend on method_missingAaron Patterson2013-07-091-1/+1
|
* Extract common query to a constant.Vipul A M2013-07-061-1/+3
| | | | Perf ref: https://gist.github.com/vipulnsward/8209749201dfdd678c97
* Remove order_values argument now that default_scope is simplifiedCarlos Antonio da Silva2013-06-281-5/+5
| | | | | | | | | | In 94924dc32baf78f13e289172534c2e71c9c8cade the internal default_scope implementation has changed making it simpler to follow, meaning that the old usage of with_default_scope has been removed. With that, order_values was the same argument for both calls to find_first_with_limit, so remove it and use the existent attribute for the sake of clarity/simplification.
* Simplify/fix implementation of default scopesJon Leighton2013-06-281-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #10898 from dmitry/find_first_refactor_duplicationRafael Mendonça França2013-06-141-11/+10
|\ | | | | Refactored ActiveRecord `first` method to get rid of duplication.
| * rename method `find_first_records` to `find_first_with_limit`Dmitry Polushkin2013-06-101-3/+3
| |
| * Refactored ActiveRecord `first` method to get rid of duplication.Dmitry Polushkin2013-06-091-11/+10
| |
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-06-141-3/+46
|\ \ | | | | | | | | | | | | Conflicts: guides/source/upgrading_ruby_on_rails.md
| * | copy edits [ci skip]Vijay Dev2013-06-141-19/+15
| | |
| * | doc: renaming table name to follow the file's standardsThiago Pinto2013-06-081-2/+2
| | |
| * | instructions for variations and alternatives for ActiveRecord#findThiago Pinto2013-06-081-1/+35
| | |
| * | explaining ActiveRecord#first in rails 3 and 4Thiago Pinto2013-06-081-0/+13
| | |
* | | we should apply the default scope before queryingAaron Patterson2013-06-121-1/+2
| | |
* | | Rather than raising ThrowResult when construct_limited_ids_conditions comes ↵Ben Woosley2013-05-101-13/+15
|/ / | | | | | | | | | | up empty, set the relation to NullRelation and rely on its results. This will help avoid errors like 2fcafee250ee2, because in most cases NullRelation will do the right thing. Minor bonus is avoiding the use of exceptions for flow control.
* | Extract JoinDependency#join_relation to DRY the repeated application of the ↵Ben Woosley2013-05-101-4/+1
| | | | | | | | #join_associations.
* | In #apply_join_dependency, we can apply the #where in-place because relation ↵Ben Woosley2013-05-101-1/+1
| | | | | | | | | | | | is always a new object. Thanks to the #except we call at the top of the method.