Class: ActiveNode::Relationship
- Inherits:
-
Object
- Object
- ActiveNode::Relationship
- Includes:
- Neography::Rest::Helpers
- Defined in:
- lib/active_node/relationship.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#other ⇒ Object
Returns the value of attribute other.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(other, props = {}) ⇒ Relationship
constructor
A new instance of Relationship.
- #new_record? ⇒ Boolean
- #save(association) ⇒ Object
Constructor Details
#initialize(other, props = {}) ⇒ Relationship
Returns a new instance of Relationship.
8 9 10 11 12 |
# File 'lib/active_node/relationship.rb', line 8 def initialize other, props={} self.other = other @hash = props.with_indifferent_access @id = @hash.delete(:id).try(&:to_i) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/active_node/relationship.rb', line 6 def id @id end |
#other ⇒ Object
Returns the value of attribute other.
5 6 7 |
# File 'lib/active_node/relationship.rb', line 5 def other @other end |
Class Method Details
.create!(n, association) ⇒ Object
34 35 36 |
# File 'lib/active_node/relationship.rb', line 34 def self.create!(n, association) new(n).save(association) end |
Instance Method Details
#new_record? ⇒ Boolean
17 18 19 |
# File 'lib/active_node/relationship.rb', line 17 def new_record? !id end |
#save(association) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_node/relationship.rb', line 21 def save(association) if new_record? from=association.owner to=other if association.reflection.direction == :incoming from, to = to, from end @id = get_id(Neo.db.create_relationship(association.reflection.type, from.id, to.id, @hash)).to_i else Neo.db.reset_relationship_properties(id, @hash.select { |_, v| v.present? }) end end |