aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation/where_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Suppress warnings of `assigned but unused variable`yui-knk2015-10-171-2/+0
|
* `where` raises ArgumentError on unsupported types.Jake Worth2015-10-161-0/+6
| | | | [#20473]
* Fix AC::Parameters not being sanitized for query methods.Guo Xiang Tan2015-10-021-0/+26
|
* Respect custom primary keys for associations in `Relation#where`Sean Griffin2015-02-041-1/+37
| | | | | | | | | | While we query the proper columns, we go through normal handling for converting the value to a primitive which assumes it should use the table's primary key. If the association specifies a different value (and we know that we're working with an association), we should use the custom primary key instead. Fixes #18813.
* Fix bind value copying from subqueried relationsSean Griffin2015-01-191-0/+8
| | | | | | | | | | | With the old implementation, the bind values were created, and then we search the attributes for `Relation` objects, and merge them. This completely ignores the order that the actual `where` clause will use. If all non-relation where parameters are before the relations, it will work. However, if we query on both a relation and a value, with the value coming second, it breaks. The order of the hash should not affect the final query (especially since hashes being ordered is an implementation detail)
* Properly copy nested bind values from subqueried relationsSean Griffin2015-01-091-9/+21
| | | | | | | | | | | This is cropping up all over the place. After a brief dive, I'm really not sure why we have `arel.bind_values` at all. A cursory grep didn't reveal where they're actually being assigned (it's definitely in AR, not in Arel). I'd like to dig further into it, as I'm fairly certain we don't actually need it, we just need a way for the predicate builder to communicate merged binds upstream. Fixes #18414
* Remove deprecated behavior allowing nested arrays as query valuesMelanie Gilman2014-12-041-6/+0
|
* Fix test which failed in isolationSean Griffin2014-11-011-0/+1
| | | | It was transitively relying on the vertex model being loaded
* Fix query with nested array in Active RecordCristian Bica2014-09-061-1/+3
| | | | | | | | `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]
* Add a test case of nested empty array values in conditionsJean Boussier2014-08-171-0/+4
| | | | | | | | | | | | Post.where(id: [[]]).to_a Used to fail with a SQL syntax error (until 4.1): SELECT ... WHERE id in (); It now properly generate: SELECT ... WHERE 1=0;
* Fixed AR::Relation#where edge case with Hash and other RelationBogdan Gusiev2014-08-141-0/+9
| | | | | | Example: Author.where(posts: { author_id: Author.where(country_id: 1) }).joins(:posts)
* active_record: Type cast booleans and durations for string columns.Dylan Thacker-Smith2014-07-061-1/+32
|
* Better support for `where()` conditions that use an association name.Martin Emde2013-12-161-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using the name of an association in `where` previously worked only if the value was a single `ActiveRecrd::Base` object. e.g. Post.where(author: Author.first) Any other values, including `nil`, would cause invalid SQL to be generated. This change supports arguments in the `where` query conditions where the key is a `belongs_to` association name and the value is `nil`, an `Array` of `ActiveRecord::Base` objects, or an `ActiveRecord::Relation` object. # Given the Post model class Post < ActiveRecord::Base belongs_to :author end # nil value finds records where the association is not set Post.where(author: nil) # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL # Array values find records where the association foreign key # matches the ids of the passed ActiveRecord models, resulting # in the same query as Post.where(author_id: [1,2]) authors_array = [Author.find(1), Author.find(2)] Post.where(author: authors_array) # ActiveRecord::Relation values find records using the same # query as Post.where(author_id: Author.where(last_name: "Emde")) Post.where(author: Author.where(last_name: "Emde")) Polymorphic `belongs_to` associations will continue to be handled appropriately, with the polymorphic `association_type` field added to the query to match the base class of the value. This feature previously only worked when the value was a single `ActveRecord::Base`. class Post < ActiveRecord::Base belongs_to :author, polymorphic: true end Post.where(author: Author.where(last_name: "Emde")) # Generates a query similar to: Post.where(author_id: Author.where(last_name: "Emde"), author_type: "Author")
* Delegate #rewhere to all on the class like all other relation methodsDavid Heinemeier Hansson2013-11-021-0/+4
|
* check class hierarchy with is_a? in PredicateBuilder.expandMikhail Dieterle2013-08-271-0/+25
| | | | add changelog entry for #11945
* Handle aliased attributes in ActiveRecord::Relation.Godfrey Chan2013-05-011-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database: With the model class Topic alias_attribute :heading, :title end The call Topic.where(heading: 'The First Topic') should yield the same result as Topic.where(title: 'The First Topic') This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`. This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`. Github #7839 *Godfrey Chan*
* Revert "Merge pull request #9207 from dylanahsmith/mysql-quote-numeric"Steve Klabnik2013-02-271-25/+0
| | | | | This reverts commit 408227d9c5ed7de26310d72a1a99c1ee02311c63, reversing changes made to dca0b57d03deffc933763482e615c3cf0b9a1d97.
* Reverting e170014113 (Change behaviour with empty hash in where clause)Guillermo Iguaran2013-02-081-6/+2
|
* Reverting 16f6f25 (Change behaviour with empty array in where clause)Guillermo Iguaran2013-02-081-3/+1
|
* Change behaviour with empty array in where clauserobertomiranda2013-02-081-1/+3
|
* Change behaviour with empty hash in where clauserobertomiranda2013-02-081-2/+6
|
* active_record: Quote numeric values compared to string columns.Dylan Smith2013-02-071-0/+25
|
* reduce the number of queries on IN clauses, fix relation queries in `where`Aaron Patterson2013-01-241-1/+14
|
* Fix syntax error and remove duplicated testCarlos Antonio da Silva2013-01-081-6/+4
|
* * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * ↵Aaron Patterson2013-01-081-0/+6
| | | | | | | | | | | | dealing with empty hashes. Thanks Damien Mathieu Conflicts: actionpack/CHANGELOG.md actionpack/lib/action_dispatch/http/request.rb actionpack/lib/action_dispatch/middleware/params_parser.rb activerecord/CHANGELOG.md activerecord/lib/active_record/relation/predicate_builder.rb activerecord/test/cases/relation/where_test.rb
* Revert "Merge branch 'master-sec'"Jeremy Kemper2013-01-081-6/+0
| | | | | This reverts commit 88cc1688d0cb828c17706b41a8bd27870f2a2beb, reversing changes made to f049016cd348627bf8db0d72382d7580bf802a79.
* * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * ↵Aaron Patterson2013-01-071-0/+6
| | | | | | | | | | | | dealing with empty hashes. Thanks Damien Mathieu Conflicts: actionpack/CHANGELOG.md actionpack/lib/action_dispatch/http/request.rb actionpack/lib/action_dispatch/middleware/params_parser.rb activerecord/CHANGELOG.md activerecord/lib/active_record/relation/predicate_builder.rb activerecord/test/cases/relation/where_test.rb
* Move where with blank conditions test to the correct where tests fileCarlos Antonio da Silva2012-12-071-0/+6
| | | | This test does not belong to has many associations test.
* fix querying with an empty hashDamien Mathieu2012-09-191-1/+10
| | | | Closes #6960
* Fix nested association referencesJon Leighton2012-09-121-38/+31
| | | | | Previously the reflection would be looked up on the wrong class. However the test passed because the examples referred back to themselves.
* Accept belongs_to assoc. keys in ActiveRecord queriesbeerlington2012-09-111-1/+69
| | | | | | | | | | | | | Allows you to specify the model association key in a belongs_to relationship instead of the foreign key. The following queries are now equivalent: Post.where(:author_id => Author.first) Post.where(:author => Author.first) PriceEstimate.where(:estimate_of_type => 'Treasure', :estimate_of_id => treasure) PriceEstimate.where(:estimate_of => treasure)
* predicate builder should not recurse for determining where columns.Aaron Patterson2012-05-301-0/+19
Thanks to Ben Murphy for reporting this CVE-2012-2661