Skip to content

Commit c13b82a

Browse files
authored
Merge pull request rails#50994 from p8/activerecord/document-alias-attribute
Document ActiveRecord `alias_attribute` [ci-skip]
2 parents f0d433b + 35bd5e0 commit c13b82a

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)