diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2013-05-01 11:33:11 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2013-05-01 16:36:01 -0700 |
commit | 54122067acaad39b277a5363c6d11d6804c7bf6b (patch) | |
tree | a6ef77805f609d5c8868602a095f49522034dd71 /activerecord/test/cases/finder_test.rb | |
parent | 09ac1776abc0d3482f491f2d49f47bcb3d9a4ad7 (diff) | |
download | rails-54122067acaad39b277a5363c6d11d6804c7bf6b.tar.gz rails-54122067acaad39b277a5363c6d11d6804c7bf6b.tar.bz2 rails-54122067acaad39b277a5363c6d11d6804c7bf6b.zip |
Handle aliased attributes in ActiveRecord::Relation.
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*
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 557cc7e7a0..7db9aef218 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -47,7 +47,8 @@ class FinderTest < ActiveRecord::TestCase def test_exists assert Topic.exists?(1) assert Topic.exists?("1") - assert Topic.exists?(:author_name => "David") + assert Topic.exists?(title: "The First Topic") + assert Topic.exists?(heading: "The First Topic") assert Topic.exists?(:author_name => "Mary", :approved => true) assert Topic.exists?(["parent_id = ?", 1]) assert !Topic.exists?(45) |