aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
...
| * Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-2/+2
| |
* | Merge pull request #29405 from kamipo/locked_should_not_build_arelRafael França2017-06-281-5/+3
|\ \ | | | | | | `Relation#locked?` should not build arel
| * | Remove delegating to arel in a relationRyuta Kamizono2017-06-291-5/+3
| |/ | | | | | | | | The delegation was needed since passing `relation` with `relation.bound_attributes`. It should use `relation.arel` in that case.
* / Extract `ordered_relation` in `FinderMethods`Ryuta Kamizono2017-06-241-12/+11
|/
* Don't eager loading if unneeded for `FinderMethods#exists?`Ryuta Kamizono2017-05-111-2/+4
| | | | Fixes #29025.
* exclude ORDER BY clause for exists? (#28699)Boris Slobodin2017-04-101-1/+1
|
* Extract `construct_relation_for_exists` in `FinderMethods`Ryuta Kamizono2017-04-091-12/+15
| | | | To ease to customize a relation for `exists?`.
* Revert "Merge pull request #28598 from wnadeau/patch-1"Rafael Mendonça França2017-04-031-1/+1
| | | | | | | | This reverts commit a680a5814184e2f37c4686aa53d0ad3c7fb6b1ee, reversing changes made to 842f67dd242e738419f27e752ea7dcd0bbe87b6d. Reason: I can't resist to the joke, so better to keep it there https://github.com/rails/rails/pull/28598#issuecomment-290945339.
* FinderMethods#fourty_two docs cite proper sourceWinfred Nadeau2017-03-291-1/+1
| | | | | | | silly method gets a silly doc fix, or I'm missing an even sillier joke and I'm about to get schooled. BUT I'm pretty sure this is some serious Beaudrillard simulacrum, though. I'm just doing my part to spread the gospel of Douglas Adams.
* Fix `find_nth` with `limit_value`Ryuta Kamizono2017-02-261-3/+7
| | | | | If the `index` exceeds a `limit`, simply return an empty result without querying the database.
* Remove duplicated private methodkami-zh2017-02-261-102/+100
|
* Fix grammar typo about sort in finder_methods.rbKevin Huang2017-01-301-2/+2
|
* Raise ArgumentError when a instance of ActiveRecord::Base is passed toRafael Mendonça França2017-01-031-7/+5
| | | | find and exists?
* Raises IrreversibleOrderError when using last with an irreversible orderRafael Mendonça França2016-12-291-8/+0
|
* Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-98/+98
| | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-12/+10
|
* Translate numeric value out of range to the specific exceptionRyuta Kamizono2016-12-061-4/+4
| | | | Raise `ActiveRecord::RangeError` when values that executed are out of range.
* Restore RecordNotFound when *_ids= can't find records by IDDominic Cleal2016-11-241-4/+4
| | | | | | | | | | | | | | | | 9c9fb19 changed the behaviour of the _ids= setters for associations to raise an AssociationTypeMismatch when unknown IDs are given: Class: <ActiveRecord::AssociationTypeMismatch> Message: <"Developer(#43811860) expected, got NilClass(#16732720)"> This restores the original ActiveRecord::RecordNotFound exception with a much clearer error message: Class: <ActiveRecord::RecordNotFound> Message: <"Couldn't find all Developers with 'id': (1, -9999) [WHERE \"contracts\".\"company_id\" = ?] (found 1 results, but was looking for 2)"> Fixes #25719
* Should except `:distinct` rather than `:order` for `exists?`Ryuta Kamizono2016-11-091-1/+1
| | | | | | | | | | | | | Records fetching order is very important for performance if `limit` is presented. Should not except the order in the case. And `exists?` replaces select list to `1 AS one` therefore `:distinct` is useless (`DISTINCT 1 AS one`). And PostgreSQL raises the following error if `:distinct` and `:order` are used in the same time. ``` ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list ```
* initialize errors with name of class and other paramsv.promzelev2016-09-231-2/+2
|
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-031-3/+3
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* Remove unnecessary ordinal methods for collection associationRyuta Kamizono2016-08-181-2/+10
| | | | | Currently `CollectionProxy` inherits `Relation` therefore we can use its own methods rather than delegating to collection association.
* Finder bang method should call non bang methodRyuta Kamizono2016-08-161-16/+16
| | | | Otherwise CollectionProxy's bang methdos cannot respect dirty target.
* Merge pull request #26097 from Dagnan/fix_recordnotfound_args_rebasedRafael França2016-08-161-4/+6
|\ | | | | When calling association.find RecordNotFound is now raised with the s…
| * When calling association.find RecordNotFound is now raised with the same ↵Michel Pigassou2016-08-131-4/+6
| | | | | | | | argument as when we do it in Record.find (primary_key, id and model).
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | Remove `find_nth_with_limit_and_offset` private methodRyuta Kamizono2016-08-151-34/+13
|/ | | | | | `find_nth` is protected method, therefore `offset` has not been passed anywhere. `find_nth_with_limit_and_offset` is unnecessary anymore because `offset` has not been passed.
* revises most Lint/EndAlignment offensesXavier Noria2016-08-071-7/+7
| | | | Some case expressions remain, need to think about those ones.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-168/+168
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-4/+4
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* `FinderMethods` uses `records` (`load_target`) when `loaded?` is trueRyuta Kamizono2016-07-281-4/+4
|
* Merge pull request #25271 from kamipo/prevent_range_error_for_existsSean Griffin2016-06-151-1/+3
|\ | | | | Prevent `RangeError` for `FinderMethods#exists?`
| * Prevent `RangeError` for `FinderMethods#exists?`Ryuta Kamizono2016-06-161-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | `FinderMethods#exists?` should return a boolean rather than raising an exception. `UniquenessValidator#build_relation` catches a `RangeError` because it includes type casting due to a string value truncation. But a string value truncation was removed at #23523 then type casting in `build_relation` is no longer necessary. aa06231 removes type casting in `build_relation` then a `RangeError` moves to `relation.exists?`. This change will remove the catching a `RangeError`.
* | Fix `calculate` with a string value in `from` and eager loadingRyuta Kamizono2016-06-131-9/+1
|/ | | | | | | | | | `construct_relation_for_association_calculations` pass a string value to `construct_join_dependency` when setting a string value in `from`. It should not pass a string value, but always `joins_values`. Related #14834, #19452. Fixes #24193.
* Exists shouldn't error when used with `includes`Sean Griffin2016-05-301-3/+3
| | | | | | | | | | | | | | | | Currently `exists?` does some hackery where it assumes that we can join onto anything that we passed to `eager_load` or `includes`, which doesn't work if we are joining onto a polymorphic association. Actually figuring out if we want to include something would require knowledge deep within the join dependency module, which is hard to pull up. The simplest solution is just to pass a flag down that says we're not actually going to try to eager load any of the data. It's not the solution I'd like, but that code really needs to be untangled before we can do much with it. This is another attempt at 6d5b1fd which should address the concerns that led to reverting it in 4ecabed.
* Pass over all Rails 5 warnings, to make sure:Vipul A M2016-04-121-2/+2
| | | | | | | | | | - we are ending sentences properly - fixing of space issues - fixed continuity issues in some sentences. Reverts https://github.com/rails/rails/commit/8fc97d198ef31c1d7a4b9b849b96fc08a667fb02 . This change reverts making sure we add '.' at end of deprecation sentences. This is to keep sentences within Rails itself consistent and with a '.' at the end.
* [ci skip] Fix the FinderMethods#find documentakihiro172016-03-141-2/+2
| | | | We should use #find_or_initialize_by and #find_or_create_by because #first_or_initialize and #first_or_create methods are not the public API
* default second_to_last to primary_key index if no order suppliedBrian Christian2016-02-271-1/+7
|
* refactor AR second_to_last to use array methodsBrian Christian2016-02-271-1/+6
|
* AR #second_to_last tests and finder methodsBrian Christian2016-02-271-4/+12
|
* Mutating the result of Relation#to_a should not affect the relationMatthew Draper2016-02-211-3/+3
| | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.
* Remove the method already overridden by private methodMehmet Emin İNAÇ2016-02-141-13/+0
|
* Merge pull request #23377 from bogdan/last-with-sqlEileen M. Uchitelle2016-02-131-9/+19
|\ | | | | Fix AR::Relation#last bugs instroduced in 7705fc
| * Make ActiveRecord::Relation#last to reverse SQL orderBogdan Gusiev2016-02-131-9/+19
| | | | | | | | instead of loading the relation into memory
* | Fix grammar `a` to `an` [ci skip]Ryuta Kamizono2016-02-131-1/+1
|/
* remove warnings from FinderMethodsyuuji.yaginuma2016-02-111-4/+4
| | | | | | | | | | | This removes the following warnings. ``` activerecord/lib/active_record/relation/finder_methods.rb:252: warning: ambiguous first argument; put parentheses or a space even after `-' operator activerecord/lib/active_record/relation/finder_methods.rb:258: warning: ambiguous first argument; put parentheses or a space even after `-' operator activerecord/lib/active_record/relation/finder_methods.rb:268: warning: ambiguous first argument; put parentheses or a space even after `-' operator activerecord/lib/active_record/relation/finder_methods.rb:274: warning: ambiguous first argument; put parentheses or a space even after `-' operator ```
* rename to 'second_to_last' and 'third_to_last'Brian Christian2016-02-101-12/+12
|
* allow Array.penultimate and Array.antepenultiate access methodsBrian Christian2016-02-091-0/+32
|
* Extract a Relation#arel_attributeMatthew Draper2016-02-041-2/+2
|
* Defer Arel attribute lookup to the model classMatthew Draper2016-02-041-2/+2
| | | | | 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.