aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation/where_clause_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-9/+9
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Revert "Change `WhereClause#merge` to same named columns on diff tables"Sean Griffin2016-01-121-15/+2
| | | | | | | | | 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-2/+15
| | | | | | | | | | | | | | | | | | | | 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]
* Post.all.or(anything) == Post.allSean Griffin2015-01-291-3/+3
|
* Bring the implementation of Relation#or up to speedSean Griffin2015-01-281-0/+20
|
* Use an `Attribute` object to represent a bind valueSean Griffin2015-01-271-8/+8
| | | | | | | | | | | The column is primarily used for type casting, which we're trying to separate from the idea of a column. Since what we really need is the combination of a name, type, and value, let's use the object that we already have to represent that concept, rather than this tuple. No consumers of the bind values have been changed, only the producers (outside of tests which care too much about internals). This is *finally* possible since the bind values are now produced from a reasonable number of lcoations.
* `WhereClause#predicates` does not need to be publicSean Griffin2015-01-271-3/+4
| | | | | | | | | | | The only place it was accessed was in tests. Many of them have another way that they can test their behavior, that doesn't involve reaching into internals as far as they did. `AssociationScopeTest` is testing a situation where the where clause would have one bind param per predicate, so it can just ignore the predicates entirely. The where chain test was primarly duplicating the logic tested on `WhereClause` directly, so I instead just make sure it calls the appropriate method which is fully tested in isolation.
* Move where grouping into `WhereClause`Sean Griffin2015-01-271-0/+33
|
* 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.