Class: Relationship

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/relationship.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.of_relation(relation) ⇒ Object



28
29
30
# File 'app/models/relationship.rb', line 28

def self.of_relation(relation)
  where(:relation => {:description => relation})
end

.starredObject



20
21
22
# File 'app/models/relationship.rb', line 20

def self.starred
  where(:starred => true)
end

.unstarredObject



24
25
26
# File 'app/models/relationship.rb', line 24

def self.unstarred
  where(:starred => false)
end

Instance Method Details

#assign_company_nameObject



14
15
16
17
18
# File 'app/models/relationship.rb', line 14

def assign_company_name
  return unless relation.description == 'employed by'
  person.company_name = other.company_name unless person.company_name.present?
  person.save!
end

#ensure_inverseObject



50
51
52
53
# File 'app/models/relationship.rb', line 50

def ensure_inverse
  create_inverse(:relation => relation.inverse, :person => other, :other => person, :inverse => self)
  save
end

#star!Object



41
42
43
44
45
46
47
48
# File 'app/models/relationship.rb', line 41

def star!
  Relationship.transaction do
    self[:starred] = true
    inverse[:starred] = true
    save!
    inverse.save!
  end
end

#unstar!Object



32
33
34
35
36
37
38
39
# File 'app/models/relationship.rb', line 32

def unstar!
  Relationship.transaction do
    self[:starred] = false
    inverse[:starred] = false
    save!
    inverse.save!
  end
end