Skip to content
  • Nikita Vasilevsky's avatar
    1818beb3
    Call proxy methods from `alias_attribute` generated methods · 1818beb3
    Nikita Vasilevsky authored
    This commit changes bodies of methods generated by `alias_attribute`
    along with generating these methods lazily.
    
    Previously the body of the `alias_attribute :new_title, :title` was
    `def new_title; title; end`. This commit changes it to
    `def new_title; attribute("title"); end`.
    
    This allows for `alias_attribute` to be used to alias attributes named
    with a reserved names like `id`:
    ```ruby
      class Topic < ActiveRecord::Base
        self.primary_key = :title
        alias_attribute :id_value, :id
      end
    
      Topic.new.id_value # => 1
    ```
    1818beb3
    Call proxy methods from `alias_attribute` generated methods
    Nikita Vasilevsky authored
    This commit changes bodies of methods generated by `alias_attribute`
    along with generating these methods lazily.
    
    Previously the body of the `alias_attribute :new_title, :title` was
    `def new_title; title; end`. This commit changes it to
    `def new_title; attribute("title"); end`.
    
    This allows for `alias_attribute` to be used to alias attributes named
    with a reserved names like `id`:
    ```ruby
      class Topic < ActiveRecord::Base
        self.primary_key = :title
        alias_attribute :id_value, :id
      end
    
      Topic.new.id_value # => 1
    ```
Loading