📜  rails class 提醒 belongs_to creator - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:48.384000             🧑  作者: Mango

代码示例2
class Task < ActiveRecord::Base
  belongs_to :soldier
  belongs_to :creator, class_name: Soldier, foreign_key: :created_by
end

class Soldier < ActiveRecord::Base
  has_many :tasks

  # Optional -- I'm unclear if you want this too?
  has_many :created_tasks, class_name: Task, foreign_key: :created_by
end