Module: Purpose::Relationship::Associations

Included in:
PlatePurpose, Purpose
Defined in:
app/models/purpose/relationship.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'app/models/purpose/relationship.rb', line 12

def self.included(base)
  base.class_eval do
    has_many :child_relationships, class_name: 'Purpose::Relationship', foreign_key: :parent_id, dependent: :destroy
    has_many :child_purposes, through: :child_relationships, source: :child

    has_many :parent_relationships, class_name: 'Purpose::Relationship', foreign_key: :child_id, dependent: :destroy
    has_many :parent_purposes, through: :parent_relationships, source: :parent
  end
end