diff options
author | sgrif <sean@thoughtbot.com> | 2013-05-17 18:23:57 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2013-07-28 13:12:20 -0600 |
commit | 92a603387c084f13a36bbf3844d89029bb73a753 (patch) | |
tree | 54a433006d02fec85e44730e00b09f84d98c91d1 /activerecord/CHANGELOG.md | |
parent | 953b577f4378df06234d7e7ff409baa4d55890e8 (diff) | |
download | rails-92a603387c084f13a36bbf3844d89029bb73a753.tar.gz rails-92a603387c084f13a36bbf3844d89029bb73a753.tar.bz2 rails-92a603387c084f13a36bbf3844d89029bb73a753.zip |
Add ability to specify how a class is converted to Arel predicate
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.
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 61dba12b64..8f7f30167d 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,13 @@ +* Add ability to define how a class is converted to Arel predicates. + For example, adding a very vendor specific regex implementation: + + regex_handler = proc do |column, value| + Arel::Nodes::InfixOperation.new('~', column, value.source) + end + ActiveRecord::PredicateBuilder.register_handler(Regexp, regex_handler) + + *Sean Griffin & @joannecheng* + * Don't allow `quote_value` to be called without a column. Some adapters require column information to do their job properly. |