aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-1/+1
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Merge pull request #24203 from sferik/count_with_blockKasper Timm Hansen2016-05-161-1/+5
|\ | | | | Forward ActiveRecord::Relation#count to Enumerable#count if block given
| * Forward ActiveRecord::Relation#count to Enumerable#count if block givenErik Michaels-Ober2016-03-191-1/+5
| |
* | 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
* | Merge pull request #24868 from vipulnsward/delegate_encode_withRafael França2016-05-051-1/+1
|\ \ | | | | | | delegate encode_with instead of to_yaml, which is deprecated
| * | delegate encode_with instead of to_yaml, which is deprecatedVipul A M2016-05-051-1/+1
| | |
* | | do not pass conditions to `#destroy_all` [ci skip]yuuji.yaginuma2016-05-051-1/+1
|/ / | | | | | | Passing conditions to `#destroy_all` was deprecated in c82c5f8.
* | Merge pull request #24317 from Gaurav2728/unused_set_in_active_recordJeremy Daer2016-04-191-1/+0
|\ \ | | | | | | | | | connection adapters column, delegation in Active Record have not use …
| * | connection adapters column, delegation in Active Record have not use of ↵Gaurav Sharma2016-03-311-1/+0
| |/ | | | | | | | | ‘set’ found these commits https://github.com/rails/rails/commit/9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6, https://github.com/rails/rails/commit/9d79334a1dee67e31222c790e231772deafcaeb8 that also should remove it.
* | Don't create new arrays when trying to compute non_empty_predicates for ↵Vipul A M2016-04-181-1/+2
| | | | | | | | | | | | where clause predicate. Get a 3-4% improvement in AST generation. Perf compare: https://gist.github.com/vipulnsward/7e4e9ecb157e574002313249a7969c82
* | Allow symbols using "dot notation" to be passed to whereSean Griffin2016-04-122-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 04ac5655be91f49cd4dfe2838df96213502fb274 I assumed that we would never want to pass the "table_name.column_name" form to where with a symbol. However, in Ruby 2.2 and later, you can quote symbols using the new hash syntax, so it's a semi-reasonable thing to do if we want to support the dot notation (which I'd rather deprecate, but that would be too painful of a migration). Instead we've changed the definition of "this is a table name with a dot" to when the value associated is a hash. It would make very little sense to write `where("table_name.column_name": { foo: :bar })` in any scenario (other than equality for a JSON column which we don't support through `where` in this way). Close #24514.
* | Pass over all Rails 5 warnings, to make sure:Vipul A M2016-04-122-3/+3
| | | | | | | | | | | | | | | | | | | | - 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.
* | Ensure associations still work when the table name contains a dotSean Griffin2016-03-312-2/+4
|/ | | | | | | | | | | | | | | This issue occured because associations now call `where` directly, and a dot in the key name for `where` means nested tables. For this fix, we now pass the table name as a symbol, and do not attempt to expand symbols containing a dot. This is a temporary fix. I do not think we should support table names containing a dot, as it has a special meaning in most backends, as well as most APIs that involve table names. This commit does not include a test, as I am going to deprecate table names containing dots in the following commit. Fixes #24367
* [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
* Merge pull request #23417 from sgringwe/masterRafael Mendonça França2016-03-011-9/+29
|\ | | | | | | Add option to error on ignored order or limit
| * Add initial support for allowing an error on order or limit of queries being ↵Scott Ringwelski2016-02-021-9/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ignored in batches add some documentation and add 4 tests regarding error vs. warning behavior fix a typo when referring to the message go back to default in tests so that ordering is not important. use a constant instead of method. fix assert_nothing_raised call. use self.klass to allow per class configuration remove logger warn assets as that is tested elsewhere. pass error_on_ignore through find_each and find_in_batches also. add blocks to the finds so that the code is actually executed put the setting back to default in an ensure Add a changelog entry
* | 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-215-7/+7
| | | | | | | | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.
* | Add methods to array delegation from `Relation`Kevin Dougherty2016-02-191-1/+2
| | | | | | | | | | | | | | | | | | | | Delegation of some `Array` methods was removed in commit 9d79334. That change did add explicit delegation of a few methods that `Array` has but which aren't on `Enumerable`. However, a few non-mutation methods were omitted. This adds `Array` delegation of `#in_groups`, `#in_groups_of`, `#shuffle` and `#split`. This allows things like `MyThing.all.in_groups_of(3) { ... }` to continue working as they did before commit 9d79334.
* | Merge pull request #22365 from ↵Sean Griffin2016-02-173-4/+70
|\ \ | | | | | | | | | | | | phuibonhoa/phuibonhoa/polymorphic_where_multiple_types Fixed `where` for polymorphic associations when passed an array containing different types.
| * | Fixed `where` for polymorphic associations when passed an array containing ↵Philippe Huibonhoa2016-02-163-4/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | different types. When passing in an array of different types of objects to `where`, it would only take into account the class of the first object in the array. PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)]) # => SELECT "price_estimates".* FROM "price_estimates" WHERE ("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" IN (1, 2)) This is fixed to properly look for any records matching both type and id: PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)]) # => SELECT "price_estimates".* FROM "price_estimates" WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1) OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
* | | 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.
* | 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-132-9/+21
|\ \ | | | | | | Fix AR::Relation#last bugs instroduced in 7705fc
| * | Make ActiveRecord::Relation#last to reverse SQL orderBogdan Gusiev2016-02-132-9/+21
| | | | | | | | | | | | 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-045-11/+11
| |
* | Defer Arel attribute lookup to the model classMatthew Draper2016-02-045-23/+13
|/ | | | | 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.
* Revert "Merge pull request #16400 from bogdan/last-with-sql"Sean Griffin2016-02-011-17/+22
| | | | | | | | | | This reverts commit 9f3730a516f30beb0050caea9539f8d6b808e58a, reversing changes made to 2637fb75d82e1c69333855abd58c2470994995d3. There are additional issues with this commit that need to be addressed before this change is ready (see #23377). This is a temporary revert in order for us to have more time to address the issues with that PR, without blocking the release of beta2.
* Reworked ActiveRecord::Relation#last to always use SQLBogdan Gusiev2016-01-281-22/+17
| | | | instead of loading relation
* Merge pull request #23303 from Empact/find-nth-deprecationRafael França2016-01-281-11/+10
|\ | | | | Consistently warn that passing an offset to `find_nth` is deprecated
| * Consistently warn that passing an offset to `find_nth` is deprecatedBen Woosley2016-01-271-11/+10
| | | | | | | | | | | | | | | | | | | | | | | | @bogdan pointed out that a `loaded?` relation would not warn that the supplied offset would be removed. This fixes that oversight. https://github.com/rails/rails/commit/16a476e4f8f802774ae7c8dca2e59f4e672dc591#commitcomment-15706834 Although this second argument is probably not widely used, and would be ignored anyway in the loaded? case, this could protect callers from gotchas. [Ben Woosley & Victor Kmita]
* | 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
* | Use bind parameters for ranges in where clausesSean Griffin2016-01-212-2/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a similar case to wanting ot use bind params for limit and offset. Right now passing a range grows the amount of prepared statements in an unbounded fashion. We could avoid using prepared statements in that case, similar to what we do with arrays, but there's a known number of variants for ranges. This ends up duplicating some of the logic from Arel for how to handle potentially infinite ranges, and that behavior may be removed from Arel in the future. Fixes #23074
* | Changed options for find_each and variants to have options start/finish ↵Vipul A M2016-01-182-47/+32
| | | | | | | | | | | | instead of start_at/end_at based on comments at https://github.com/rails/rails/pull/12257#issuecomment-74688344
* | Properly include the `from` clause when merging relationsSean Griffin2016-01-141-0/+3
| | | | | | | | | | | | | | | | | | | | The code that set the from clause was removed in bdc5141652770fd227455681cde1f9899f55b0b9. I did not give any reason for doing so. My assumption was that I intended to change it to use the clause objects, but forgot. We appeared to not have test coverage for this case. Fixes #22996
* | 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]
* | Revert "Change `WhereClause#merge` to same named columns on diff tables"Sean Griffin2016-01-121-10/+11
| | | | | | | | | | | | | | | | | | This reverts commit 5d41cb3bfd6b19833261622ce5d339b1e580bd8b. This implementation does not properly handle cases involving predicates which are not associated with a bind param. I have the fix in mind, but don't have time to implement just yet. It will be more similar to #22823 than not.
* | Change `WhereClause#merge` to same named columns on diff tablesSean Griffin2016-01-121-11/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the predicates are an arel equality node where the left side is a full arel attribute, the binds just have the name of the column and nothing else. This means that while splitting the predicates can include the table as a factor, the binds cannot. It's entirely possible that we might be able to have the bind params carry a bit more information (I don't believe the name is used for anything but logging), and that is probably a worthwhile change to make in the future. However the simplest (and likely slightly faster) solution is to simply use the indices of the conflicts in both cases. This means that we only have to compute the collision space once, instead of twice even though we're doing an additional array iteration. Regardless, this method isn't a performance hotspot. Close #22823. [Ben Woosley & Sean Griffin]
* | activerecord: reuse immutable objectsTamir Duberstein2016-01-043-12/+14
| |
* | activerecord: allocate fewer arrays in `RecordFetchWarning`Tamir Duberstein2016-01-041-6/+4
| |
* | Merge pull request #22877 from kamipo/refactor_case_sensitive_comparisonRafael França2016-01-011-0/+1
|\ \ | | | | | | Refactor `case_{sensitive|insensitive}_comparison`
| * | Refactor `case_{sensitive|insensitive}_comparison`Ryuta Kamizono2016-01-011-0/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ``` SELECT 1 AS one FROM "topics" WHERE "topics"."title" = 'abc' LIMIT $1 [["LIMIT", 1]] ``` After: ``` SELECT 1 AS one FROM "topics" WHERE "topics"."title" = $1 LIMIT $2 [["title", "abc"], ["LIMIT", 1]] ```
* / Improve example of #or to use different column values in the where clausesTim Sandberg2015-12-301-2/+2
|/
* Fix `first(limit)` to take advantage of `loaded?` records if availableBen Woosley2015-12-241-5/+20
| | | | | | | | | | | | | | | | | I realized that `first(2)`, etc. was unnecessarily querying for the records when they were already preloaded. This was because `find_nth_with_limit` can not know which `@records` to return because it conflates the `offset` and `index` into a single variable, while the `@records` only needs the `index` itself to select the proper record. Because `find_nth` and `find_nth_with_limit` are public methods, I instead introduced a private method `find_nth_with_limit_and_offset` which is called internally and handles the `loaded?` checking. Once the `offset` argument is removed from `find_nth`, `find_nth_with_limit_and_offset` can be collapsed into `find_nth_with_limit`, with `offset` always equal to `offset_index`.