aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/predicate_builder
Commit message (Collapse)AuthorAgeFilesLines
...
* Refactor association handling in `PredicateBuilder`Sean Griffin2014-12-261-0/+57
| | | | | | | | | | I'm attempting to remove `klass` as a dependency of the predicate builder, in favor of an object that better represents what we're using it for. The only part of this which doesn't fit nicely into that picture is the check for an association being polymorphic. Since I'm not yet sure what that is going to look like, I've moved this logic into another class in an attempt to separate things that will change from things that won't.
* Re-use the predicate builder in the `ArrayHandler`Sean Griffin2014-12-261-3/+11
| | | | | | | | | | This reduces the number of places which will need to care about single value or range specific logic as we introduce type casting. The array handler is only responsible for producing `in` statements. /cc @mrgilman [Sean Griffin & Melanie Gilman]
* Change `PredicateBuilder` handler methods to instance methodsSean Griffin2014-12-264-0/+46
| | | | | | | | | | | | 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]
* Add missing `:nodoc:`Sean Griffin2014-12-261-1/+1
| | | | | We're accidentally documenting `PredicateBuilder` and `ArrayHandler` since there's a constant which is missing `# :nodoc:`
* Remove deprecated behavior allowing nested arrays as query valuesMelanie Gilman2014-12-041-10/+0
|
* 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.
* Use `#between`, rather than `#in` for passing Ranges to ArelSean Griffin2014-10-301-1/+1
| | | | Passing ranges to `#in` has been deprecated in Arel.
* let's warn with heredocsXavier Noria2014-10-281-3/+8
| | | | | | | | | | | | 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.
* 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]
* Allow empty arrays in where predicatesSean Griffin2014-05-261-0/+2
|
* Refactor the handling of arrays in where predicatesSean Griffin2014-05-261-11/+14
| | | | | | Simplifies the code slightly, isolates non-nil non-range values into a single array, which will make it easier to do things like apply type casting to them in the future.
* Add ability to specify how a class is converted to Arel predicatesgrif2013-07-282-0/+42
This adds the ability for rails apps or gems to have granular control over how a domain object is converted to sql. One simple use case would be to add support for Regexp. Another simple case would be something like the following: class DateRange < Struct.new(:start, :end) def include?(date) (start..end).cover?(date) end end class DateRangePredicate def call(attribute, range) attribute.in(range.start..range.end) end end ActiveRecord::PredicateBuilder.register_handler(DateRange, DateRangePredicate.new) More complex cases might include taking a currency object and converting it from EUR to USD before performing the query. By moving the existing handlers to this format, we were also able to nicely refactor a rather nasty method in PredicateBuilder.