aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* Fix includes on association with a scope containing joins along with conditionssiddharth@vinsol.com2014-11-211-4/+2
| | | | on the joined assoiciation
* PERF: avoid string allocationsSam2014-11-201-1/+6
|
* Remove the unused second argument to `substitute_at`Sean Griffin2014-11-171-12/+0
| | | | Oh hey, we got to remove some code because of that!
* rm `reorder_bind_params`Sean Griffin2014-11-171-10/+0
| | | | | | Arel handles this for us automatically. Updated tests, as BindParam is no longer a subclass of SqlLiteral. We should remove the second argument to substitute_at entirely, as it's no longer used
* Handle `RangeError` from casting in `find_by` and `find_by!` on RelationSean Griffin2014-11-021-0/+4
| | | | | We should not behave differently just because a class has a default scope.
* Pass the `SelectManager`, rather than the AST when querying w/ RelationSean Griffin2014-11-021-1/+1
| | | | | | Arel specifically handles `SelectManager`, with the same logic we're currently performing. The AST is `Enumerable`, which Arel looks for separately now.
* Don't duplicate predicate building logic in Relation findersSean Griffin2014-11-011-5/+2
|
* Use a bound parameter for the "id = " portion of update statementsSean Griffin2014-11-011-3/+6
| | | | | | We need to re-order the bind parameters since the AST returned by the relation will have the where statement as the first bp, which breaks on PG.
* Correctly cast calculation results on PGSean Griffin2014-11-011-1/+2
| | | | | MySQL reports the column name as `"MAX(developer_id)"`. PG will report it as `"max"`
* [ci skip] `Relation#bind` is not public APISean Griffin2014-11-011-1/+1
|
* Use bind values for joined tables in where statementsSean Griffin2014-11-011-0/+17
| | | | | | | | | | | | | | | In practical terms, this allows serialized columns and tz aware columns to be used in wheres that go through joins, where they previously would not behave correctly. Internally, this removes 1/3 of the cases where we rely on Arel to perform type casting for us. There were two non-obvious changes required for this. `update_all` on relation was merging its bind values with arel's in the wrong order. Additionally, through associations were assuming there would be no bind parameters in the preloader (presumably because the where would always be part of a join) [Melanie Gilman & Sean Griffin]
* Remove redundant substitute index when constructing bind valuesMelanie Gilman2014-10-311-5/+4
| | | | | | We end up re-ordering them either way when we construct the Arel AST (in order to deal with rewhere, etc), so we shouldn't bother giving it a number in the first place beforehand.
* Treat strings greater than int max value as out of rangeSean Griffin2014-10-311-0/+2
| | | | | | | | | | | Sufficiently large integers cause `find` and `find_by` to raise `StatementInvalid` instead of `RecordNotFound` or just returning `nil`. Given that we can't cast to `nil` for `Integer` like we would with junk data for other types, we raise a `RangeError` instead, and rescue in places where it would be highly unexpected to get an exception from casting. Fixes #17380
* Don't require calculations to be aliased to a columnSean Griffin2014-10-311-1/+1
| | | | | | | Arel has changed so that `.sum` no longer aliases `SUM(the_column)` to `sum_id`. This means the type returned by the adapter will be at the key `"SUM(the_column)"`. Longer term, we should eventually be able to retain type information from the AR::Base subclasses used in joined queries
* Use `#between`, rather than `#in` for passing Ranges to ArelSean Griffin2014-10-302-2/+2
| | | | Passing ranges to `#in` has been deprecated in Arel.
* Merge pull request #17421 from rails/warn-with-heredocXavier Noria2014-10-283-9/+22
|\ | | | | let warn with heredocs
| * let's warn with heredocsXavier Noria2014-10-283-9/+22
| | | | | | | | | | | | | | | | | | | | | | | | The current style for warning messages without newlines uses concatenation of string literals with manual trailing spaces where needed. Heredocs have better readability, and with `squish` we can still produce a single line. This is a similar use case to the one that motivated defining `strip_heredoc`, heredocs are super clean.
* | Remove unneccessary default values from relation mergerSean Griffin2014-10-281-2/+2
| | | | | | | | The value methods will default to an empty array for us automatically
* | Call value methods when merging relations, rather than accessing keysSean Griffin2014-10-281-14/+14
|/ | | | | | | | The change to accessing keys directly was originally added to allow `merge` to take a hash. The implementation of `HashMerger` no longer requires us to be doing so. Accessing the values directly makes it impossible to change internal storage details, even if shim methods are added temporarily
* Allow Relation#rewhere to work with infinite range valuesDan Olson2014-10-271-1/+1
|
* Fix Relation.rewhere to work with Range valuesDan Olson2014-10-201-1/+1
|
* [ci skip] Make merge method nodocAnshul Sharma2014-10-201-8/+1
|
* [ci skip] merge docsAnshul Sharma2014-10-201-0/+7
|
* Remove duplicate error message "Couldn't find..."claudiob2014-10-131-6/+10
| | | | | | | | | This commit removes the duplication of the error message: > Couldn't find #{@klass.name} with [#{arel.where_sql}] introduced in #15791 by adding a private method `find_nth!` that deals with all the method like `first!` and `second!`.
* No need to call to_sym hereGodfrey Chan2014-09-202-9/+9
| | | | | The hash is now string-keyed, and [_]reflect_on_association calls `to_s` on the argument anyway.
* Merge pull request #15791 from zev/add_model_to_recordnotfound_messageAaron Patterson2014-09-191-8/+8
|\ | | | | Update RecordNotFound exception cases to include a message with the
| * Update RecordNotFound exception cases to include a message with theZev Blut2014-06-181-8/+8
| | | | | | | | Model that the Record was not found in.
* | A `NullRelation` should represent nothing. Closes #15176.Yves Senn2014-09-111-2/+2
| | | | | | | | | | | | [Matthew Draper & Yves Senn] Closes #16860. (pull request to discuss the implementation)
* | Fix query with nested array in Active RecordCristian Bica2014-09-061-4/+12
| | | | | | | | | | | | | | | | `User.where(id: [[1,2],3])` was equal to `User.where(id:[1, 2, 3])` in Rails 4.1.x but because of some refactoring in Arel this stopped working in 4.2.0. This fixes it in Rails. [Dan Olson & Cristian Bica]
* | Fixed regression with referencing polymorphic assoc in eager-loadGodfrey Chan2014-09-051-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | This is cased by 03118bc + 9b5d603. The first commit referenced the undefined local variable `column` when it should be using `reflection.type` as the lookup key. The second commit changed `build_arel` to not modify the `bind_values` in- place so we need to combine the arel's `bind_values` with the relation's when building the SQL. Fixes #16591 Related #15821 / #15892 / 7aeca50
* | always reorder bind parameters. fixes #15920Aaron Patterson2014-09-041-6/+4
| |
* | Avoid using heredoc for user warningsGodfrey Chan2014-08-281-4/+2
| | | | | | | | | | | | | | | | | | | | Using heredoc would enforce line wrapping to whatever column width we decided to use in the code, making it difficult for the users to read on some consoles. This does make the source code read slightly worse and a bit more error-prone, but this seems like a fair price to pay since the primary purpose for these messages are for the users to read and the code will not stick around for too long.
* | Fixes the `Relation#exists?` to work with polymorphic associations.Kassio Borges2014-08-181-1/+1
| | | | | | | | Fixes #15821.
* | Check attributes passed to create_with and whereRafael Mendonça França2014-08-181-2/+14
| | | | | | | | | | | | | | | | | | | | | | If the request parameters are passed to create_with and where they can be used to do mass assignment when used in combination with Relation#create. Fixes CVE-2014-3514 Conflicts: activerecord/lib/active_record/relation/query_methods.rb
* | Fixed AR::Relation#where edge case with Hash and other RelationBogdan Gusiev2014-08-141-3/+15
| | | | | | | | | | | | Example: Author.where(posts: { author_id: Author.where(country_id: 1) }).joins(:posts)
* | remove blank lines in the start of the ActiveRecord filesPonomarev Nikolay2014-07-291-1/+0
| |
* | Fix typo in commentCade Truitt2014-07-021-1/+1
| |
* | Encapsulate knowledge of type objects on `ActiveRecord::Result`Sean Griffin2014-06-221-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Attempting to reduce the number of places that care about the details of how type casting occurs. We remove the type casting of the primary key in `JoinDependecy`, rather than encapsulating it. It was originally added for consistency with https://github.com/rails/rails/commit/40898c8c19fa04442fc5f8fb5daf3a8bdb9a1e03#diff-06059df8d3dee3101718fb2c01151ad0R211, but that conditional was later removed in https://github.com/rails/rails/commit/d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734. What is important is that the same row twice will have the same value for the primary key, which it will.
* | Don't use `Column` for type casting in Relation calculationsSean Griffin2014-06-181-12/+8
| |
* | [ci skip] add API doc for AR Group.Aditya Kapoor2014-06-171-1/+9
| |
* | Pluck should work with columns of the same name from different tablesSean Griffin2014-06-111-3/+1
|/ | | | | | | | The column name given by the adapter doesn't include the table namespace, so going through the hashed version of the result set causes overridden keys. Fixes #15649
* ActiveRecord::FinderMethods.find passes proc parameter #15382James Yang2014-06-101-1/+1
|
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-2/+2
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* reuse available belongs_to? methodeileencodes2014-06-031-1/+1
| | | | | | | | | | Reflection has a `belongs_to?` method. Instead of checking for `macro == :belongs_to` throughout the source reuse existing method. I also bumped `foreign_key_present?` method onto on line because the `belongs_to?` makes it shorter than other longer lines in the same class.
* Remove unused `initialize_attributes` methodSean Griffin2014-06-021-1/+1
| | | | | This was previously a hook for a special case related to `serialize`, which has since been removed.
* Merge pull request #14834 from al2o3cr/issue14155Aaron Patterson2014-05-271-1/+10
|\ | | | | Correctly alias table names when joining more than once
| * WIP: pass existing joins to construct_join_dependencyMatt Jones2014-05-161-1/+10
| |
* | Allow empty arrays in where predicatesSean Griffin2014-05-261-0/+2
| |
* | Merge pull request #15300 from arthurnn/refactor_reflectionsRafael Mendonça França2014-05-262-3/+3
|\ \ | | | | | | Refactor reflections
| * | Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-242-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Fix habtm reflection Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/counter_cache.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/reflection_test.rb