Sha256: 66238e03e643f2b774a0ad38333e25551614853f6386c4696ba7aff6b75b60d8

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

# to do 
# instead of creating a class, use a module which is included on startup
# then, after specifying the namespace and before autoaccolating the database-classes create the proper E-Base-class and include this stuff
class E  < ActiveOrient::Model
  ## link to the library-class
  class << self
=begin
establish contrains on Edges

Edges are uniq!

Creates individual indices for child-classes if applied to the class itself.
=end
  def  uniq_index
    create_property  :in,  type: :link, linked_class: :V
    create_property  :out, type: :link, linked_class: :V
    create_index "#{ref_name}_idx", on: [ :in, :out ]
  end
=begin
  Instantiate a new Edge between two Vertices 

  The parameters »from« **or** »to« can take a list of model-records. Then subsequent edges are created.

  :call-seq:
  Model.create from:, to:,  attributes:{}
=end


  def create  **keyword_arguments
    new_edge = db.create_edge self, **keyword_arguments
    new_edge =  new_edge.pop if new_edge.is_a?( Array) && new_edge.size == 1
 #   to.reload! if to.is_a? ActiveOrient::Model
 #   from.reload! if from.is_a? ActiveOrient::Model
    # vertices must be reloaded

    new_edge # returns the created edge (or an array of created edges
  end

=begin
Edge#delete fires a "delete edge" command to the database.
The where statement can be empty ( "" or {}"), then all edges are removed 

The rid-cache is reseted, too
=end
  def delete where: 
    db.execute { "delete edge #{ref_name} #{db.compose_where(where)}" }
    reset_rid_store
  end
  
  # remove works on record-level
  end 
  def remove
    db.delete_edge self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active-orient-0.6 lib/model/edge.rb