From 54122067acaad39b277a5363c6d11d6804c7bf6b Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Wed, 1 May 2013 11:33:11 -0700 Subject: 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* --- activerecord/test/cases/finder_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/finder_test.rb') 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) -- cgit v1.2.3