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/models | |
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/models')
-rw-r--r-- | activerecord/test/models/company.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 3ca8f69646..dcda62e71d 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -206,6 +206,8 @@ class Account < ActiveRecord::Base belongs_to :firm, :class_name => 'Company' belongs_to :unautosaved_firm, :foreign_key => "firm_id", :class_name => "Firm", :autosave => false + alias_attribute :available_credit, :credit_limit + def self.destroyed_account_ids @destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] } end |