rails class reminders belongs_to creator code example

Example 1: rails class reminders belongs_to creator

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

Example 2: rails class reminders belongs_to creator

class Task < ActiveRecord::Base
  belongs_to :soldier
  belongs_to :creator, class_name: 'Soldier', foreign_key: :created_by
end

Tags:

Ruby Example