Rails has_many with alias name

前端 未结 5 2142
忘掉有多难
忘掉有多难 2020-12-12 09:36

In my User model I could have:

has_many :tasks

and in my Task model:

belongs_to :user

Then, supposing the

5条回答
  •  不思量自难忘°
    2020-12-12 10:13

    You could also use alias_attribute if you still want to be able to refer to them as tasks as well:

    class User < ActiveRecord::Base
      alias_attribute :jobs, :tasks
    
      has_many :tasks
    end
    

提交回复
热议问题