aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation
Commit message (Collapse)AuthorAgeFilesLines
...
* Move the `from` bind logic to a `FromClause` classSean Griffin2015-01-261-3/+3
| | | | | | | Contrary to my previous commit message, it wasn't overkill, and led to much cleaner code. [Sean Griffin & anthonynavarre]
* Remove `Relation#bind_values=`Sean Griffin2015-01-261-1/+1
| | | | | | | | | | The last place that was assigning it was when `from` is called with a relation to use as a subquery. The implementation was actually completely broken, and would break if you called `from` more than once, or if you called it on a relation, which also had its own join clause, as the bind values would get completely scrambled. The simplest solution was to just move it into its own array, since creating a `FromClause` class for this would be overkill.
* Remove all references to `where_values` in testsSean Griffin2015-01-252-39/+39
|
* Move `where_unscoping` logic over to `WhereClause`Sean Griffin2015-01-251-0/+14
|
* Move `where.not` logic into `WhereClause`Sean Griffin2015-01-251-0/+26
|
* Remove all references to `where_values` in association codeSean Griffin2015-01-251-0/+5
|
* Move where merging logic over to `WhereClause`Sean Griffin2015-01-251-0/+42
| | | | | | This object being a black box, it knows the details of how to merge itself with another where clause. This removes all references to where values or bind values in `Relation::Merger`
* Introduce `Relation::WhereClause`Sean Griffin2015-01-251-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The way that bind values are currently stored on Relation is a mess. They can come from `having`, `where`, or `join`. I'm almost certain that `having` is actually broken, and calling `where` followed by `having` followed by `where` will completely scramble the binds. Joins don't actually add the bind parameters to the relation itself, but instead add it onto an accessor on the arel AST which is undocumented, and unused in Arel itself. This means that the bind values must always be accessed as `relation.arel.bind_values + relation.bind_values`. Anything that doesn't is likely broken (and tons of bugs have come up for exactly that reason) The result is that everything dealing with `Relation` instances has to know far too much about the internals. The binds are split, combined, and re-stored in non-obvious ways that makes it difficult to change anything about the internal representation of `bind_values`, and is extremely prone to bugs. So the goal is to move a lot of logic off of `Relation`, and into separate objects. This is not the same as what is currently done with `JoinDependency`, as `Relation` knows far too much about its internals, and vice versa. Instead these objects need to be black boxes that can have their implementations swapped easily. The end result will be two classes, `WhereClause` and `JoinClause` (`having` will just re-use `WhereClause`), and there will be a single method to access the bind values of a `Relation` which will be implemented as ``` join_clause.binds + where_clause.binds + having_clause.binds ``` This is the first step towards that refactoring, with the internal representation of where changed, and an intermediate representation of `where_values` and `bind_values` to let the refactoring take small steps. These will be removed shortly.
* 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)
* Whether a column exists or not doesn't affect whether we can use bindsSean Griffin2015-01-191-1/+1
| | | | | | Looking through the blame, this logic used to be when we actually created the bind tuple. My guess is that `nil` couldn't be handled there at that time. It can, now.
* Should escape regexp wildcard character `.`Ryuta Kamizono2015-01-191-1/+1
| | | | | `.` is regexp meta character. It should be escape for `assert_match` correctly.
* 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 all cases of manuallly wrapping `Arel::Nodes::Quoted`Sean Griffin2014-12-291-2/+2
| | | | | | | | | | This is no longer required now that we are injecting a type caster object into the Arel table, with the exception of uniqueness validations. Since it calls `ConnectionAdapter#type_cast`, the value has already been cast for the database. We don't want Arel to attempt to cast it further, so we need to continue wrapping it in a quoted node. This can potentially go away when this validator is refactored to make better use of `where` or the predicate builder.
* Fix failing testsSean Griffin2014-12-291-8/+4
|
* Inform Arel we don't need additional type casting in testsSean Griffin2014-12-262-3/+3
| | | | | | | Part of the larger refactoring to remove type casting from Arel. We can inform it that we already have the right type by wrapping the value in an `Arel::Nodes::Quoted`. This commit can be reverted when we have removed type casting from Arel in Rail 5.1
* Eagerly cast array values passed to the predicate builderSean Griffin2014-12-261-2/+6
| | | | | | | | Part of a larger refactoring to remove type casting from Arel. /cc @mrgilman [Sean Griffin & Melanie Gilman]
* Perform casting of single values within the predicate builderSean Griffin2014-12-261-1/+1
| | | | | | | | | | | As part of the larger refactoring to remove type casting from Arel, we need to do the casting of values eagerly. The predicate builder is the closest place that knows about the Active Record class, and can therefore have the type information. /cc @mrgilman [Sean Griffin & Melanie Gilman]
* Fix new warning in ruby 2.2Sean Griffin2014-12-261-2/+2
|
* Change `PredicateBuilder` handler methods to instance methodsSean Griffin2014-12-261-1/+3
| | | | | | | | | | | | This will allow us to pass the predicate builder into the constructor of these handlers. The procs had to be changed to objects, because the `PredicateBuilder` needs to be marshalable. If we ever decide to make `register_handler` part of the public API, we should come up with a better solution which allows procs. /cc @mrgilman [Sean Griffin & Melanie Gilman]
* Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-1/+1
| | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* Remove deprecated behavior allowing nested arrays as query valuesMelanie Gilman2014-12-041-6/+0
|
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Fix test which failed in isolationSean Griffin2014-11-011-0/+1
| | | | It was transitively relying on the vertex model being loaded
* Allow Relation#rewhere to work with infinite range valuesDan Olson2014-10-271-0/+21
|
* Fix Relation.rewhere to work with Range valuesDan Olson2014-10-201-0/+7
|
* A `NullRelation` should represent nothing. Closes #15176.Yves Senn2014-09-111-0/+4
| | | | | | [Matthew Draper & Yves Senn] Closes #16860. (pull request to discuss the implementation)
* 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]
* Load :developers fixtures where expecting a Developer to be thereAkira Matsuda2014-09-051-1/+1
|
* "warning: assigned but unused variable"Akira Matsuda2014-08-211-1/+1
|
* Only merge scopes with zero arity in has_many throughAgis-2014-08-201-0/+13
| | | | | | | | | | | | | | | with dynamic conditions. Fixes #16128 This bug was introduced in https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d so it's present from 4.1.2-rc1 and after. https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d merges any relation scopes passed as proc objects to the relation, but does *not* take into account the arity of the lambda. To reproduce: https://gist.github.com/Agis-/5f1f0d664d2cd08dfb9b
* 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
|
* Remove duplicated parameter check on #where!Sergey Alekseev2014-05-231-1/+1
| | | | | | | | | | It seems that #where! is not designed to be used as a chained where. See initial implementation at 8c2c60511beaad05a218e73c4918ab89fb1804f0. So, no need to check twice. We should not test #where! https://github.com/rails/rails/pull/15285#discussion_r13018316
* Merge pull request #15078 from nbudin/fix_merger_filter_binds_comparison_masterRafael Mendonça França2014-05-141-0/+5
|\ | | | | | | | | | | | | Make filter_binds filter out symbols that are equal to strings Conflicts: activerecord/CHANGELOG.md
| * Make filter_binds filter out symbols that are equal to stringsNat Budin2014-05-141-0/+5
|/ | | | | | | | | | | | | ActiveRecord::Relation::Merger's filter_binds method does not filter out bind variables when one of the attribute nodes has a string name, but the other has a symbol name, even when those names are actually equal. This can result in there being more bind variables than placeholders in the generated SQL. This is particularly an issue for PostgreSQL, where this is treated as an error. This patch changes the filter_binds method to make it convert both attribute names to strings before comparing.
* Modify assert conditions not to be affectedYasuo Honda2014-05-121-2/+3
| | | | by each database bind variable naming conventions
* Put back Relation#join method as a delegate to ArrayBogdan Gusiev2014-05-051-1/+1
| | | | | | | | This is a regression 4.0 -> 4.1 fix. In 4.1.0 Relation#join is delegated to Arel#SelectManager. In 4.0 series it is delegated to Array#join This patch puts back the behaviour of 4.0
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-251-1/+6
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (28 commits) move AR length validation tests into separate test-case. No need for trailing slash on migration path. reset `@arel` when modifying a Relation in place. PostgreSQL Timestamps always map to `:datetime`. [ci skip] Improve formatting and yml Fix a typo in the doc of forty_two AR FinderMethod Improve readability of contributing to rails guide. [ci skip] Precompile the image we're referencing, too. `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions. Fixed an issue with migrating legacy json cookies. Correct comment [ci skip] Perfer to define methods instead of calling test Fix syntax error Add CHANGELOG entry for #14757 [ci skip] Fix run-on sentences and improve grammar [skip ci] Add test for using ActionView::Helpers::FormHelper.label with block and html select! renamed to avoid name collision Array#select! Rearrange deck chairs on the titanic. Organize connection handling test cases. Change favicon_link_tag helper mimetype from image/vnd.microsoft.icon to image/x-icon. ActionController::Renderers documentation fix ...
| * select! renamed to avoid name collision Array#select!Earl J St Sauver2014-04-211-1/+6
| | | | | | | | | | | | | | | | Fixes #14752 Select mimics the block interface of arrays, but does not mock the block interface for select!. This change moves the api to be a private method, _select!.
* | remove the bind substitution visitor. to_sql should never return bind valuesAaron Patterson2014-04-091-3/+1
| |
* | Merge branch 'master' into adequaterecordAaron Patterson2014-04-071-3/+11
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (122 commits) Rails.application should be set inside before_configuration hook remove check for present? from delete_all Remove useless begin..end Build the reverse_order on its proper method. Use connection-specific bytea escaping Ignore order when doing count. make enums distinct per class Remove unused `subclass_controller_with_flash_type_bar` var from flash test. fix CollectionProxy delete_all documentation Added OS X specific commands to installation guide [ci skip] Recommended using homebrew for installing MySQL and PostgreSQL Fix setup of adding _flash_types test. Use SVG version of travis build status badge [skip ci] W3C CSP document moved to gihub.io URL [ci skip] sprockets-rails was released Fix the test defining the models in the right place Add CHANGELOG entry for #11650 [ci skip] Declare the assets dependency Use sass-rails 4.0.3 Make possible to use sprockets-rails 2.1 add missing parentheses to validates_with documentation [skip ci] ...
| * Build the reverse_order on its proper method.Lauro Caetano2014-04-071-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The reverse_order method was using a flag to control if the order should be reversed or not. Instead of using this variable just build the reverse order inside its proper method. This implementation was leading to an unexpected behavior when using reverse_order and then applying reorder(nil). Example: Before Post.order(:name).reverse_order.reorder(nil) # => SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC After Post.order(:name).reverse_order.reorder(nil) # => SELECT "posts".* FROM "posts"
* | Merge branch 'master' into adequaterecordAaron Patterson2014-03-252-6/+6
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (96 commits) clarify CHANGELOG [ci skip]. Fix Generation of proper migration when ActiveRecord::Base.pluralize_table_names = false. update comments to reflect that options support is not available synchronize changelogs and 4.1 release notes. [ci skip] do not rely on method_missing hitting arel use ARel factory methods for building AST nodes Fix date_select option overwriting html classes - Rename `increment_or_decrement` to an apt `set_cache_value` since it actually doesn't increment/decrement in localstore. Check if any sqlite files are not included in the gitignore Remove sqlite3 lines from .gitignore if the application is not using sqlite3. Adding active_model in Rails::Info Clean up tables after each test. Swapped parameters of assert_equal in assert_select Update test helper to use latest Digestor API Digestor should just rely on the finder to know about the format and the variant -- trying to pass it back in makes a mess of things (oh, and doesnt work) Log the full path, including variant, that the digestor is trying to find Fix for digestor to consider variants for partials -- this still needs more testing!! fix log_tags request object grammar Extract with_example_table into helper method. test for structure:dump without schema information table. refs eafec46 ... Conflicts: activerecord/test/cases/relation/where_chain_test.rb
| * use ARel factory methods for building AST nodesAaron Patterson2014-03-242-17/+17
| | | | | | | | This abstracts us from the actual construction of the nodes
* | Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-0/+4
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
| * Handle aliased attributes in AR::Relation#select, #order, etc.Tsutomu Kuroda2014-01-291-0/+4
| | | | | | | | | | | | | | With this we can write `Model#select(:aliased)`, `Model#order(:aliased)`, `Model#reoder(aliased: :desc)`, etc. Supplementary work to 54122067acaad39b277a5363c6d11d6804c7bf6b.
* | Merge branch 'master' into set_bindsAaron Patterson2014-01-141-2/+2
|\| | | | | | | | | | | | | | | * master: rm dup code Conflicts: activerecord/test/cases/relations_test.rb
* | remove dead codeAaron Patterson2014-01-141-3/+0
| |
* | adjust AST tests to respect bind valuesAaron Patterson2014-01-141-21/+61
| |