link.rb 452 B

1234567891011
  1. # A Link connects Agents in a directed Event flow from the `source` to the `receiver`.
  2. class Link < ActiveRecord::Base
  3. belongs_to :source, class_name: "Agent", inverse_of: :links_as_source
  4. belongs_to :receiver, class_name: "Agent", inverse_of: :links_as_receiver
  5. before_create :store_event_id_at_creation
  6. def store_event_id_at_creation
  7. self.event_id_at_creation = source.events.limit(1).reorder("id desc").pluck(:id).first || 0
  8. end
  9. end