Rails association with multiple foreign keys

前端 未结 6 1768
情深已故
情深已故 2020-11-28 02:21

I want to be able to use two columns on one table to define a relationship. So using a task app as an example.

Attempt 1:

class Use         


        
6条回答
  •  天命终不由人
    2020-11-28 02:51

    Since Rails 5 you can also do that which is the ActiveRecord safer way:

    def tasks
      Task.where(owner: self).or(Task.where(assignee: self))
    end
    

提交回复
热议问题