link.rb 508 B

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