method

alias_attribute

Importance_1
v8.0.0 - Show latest stable - 0 notes - Class: ActiveRecord::AttributeMethods::ClassMethods
alias_attribute(new_name, old_name) public

Allows you to make aliases for attributes.

class Person < ActiveRecord::Base
  alias_attribute :nickname, :name
end

person = Person.create(name: 'Bob')
person.name     # => "Bob"
person.nickname # => "Bob"

The alias can also be used for querying:

Person.where(nickname: "Bob")
# SELECT "people".* FROM "people" WHERE "people"."name" = "Bob"
Show source
Register or log in to add new notes.