Rails has_many with alias name

前端 未结 5 2122
忘掉有多难
忘掉有多难 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:18

    You could do this two different ways. One is by using "as"

    has_many :tasks, :as => :jobs
    

    or

    def jobs
         self.tasks
    end
    

    Obviously the first one would be the best way to handle it.

提交回复
热议问题