Skip to content

Commit 35bd5e0

Browse files
committed
Document ActiveRecord alias_attribute [ci-skip]
This documents how `alias_attribute` works, including for queries.
1 parent f0d433b commit 35bd5e0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

activerecord/lib/active_record/attribute_methods.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ def initialize_generated_modules # :nodoc:
4949
super
5050
end
5151

52+
# Allows you to make aliases for attributes.
53+
#
54+
# class Person < ActiveRecord::Base
55+
# alias_attribute :nickname, :name
56+
# end
57+
#
58+
# person = Person.create(name: 'Bob')
59+
# person.name # => "Bob"
60+
# person.nickname # => "Bob"
61+
#
62+
# The alias can also be used for querying:
63+
#
64+
# Person.where(nickname: "Bob")
65+
# # SELECT "people".* FROM "people" WHERE "people"."name" = "Bob"
5266
def alias_attribute(new_name, old_name)
5367
super
5468

0 commit comments

Comments
 (0)