Class: Dart::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/dart/core/relation.rb

Direct Known Subclasses

Database::Relation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, columns) ⇒ Relation

Returns a new instance of Relation.



8
9
10
11
12
# File 'lib/dart/core/relation.rb', line 8

def initialize(table, columns)
  @table_name   = table.to_s.freeze
  @column_names = columns.map(&:to_s).map(&:freeze)
  @associations = []
end

Instance Attribute Details

#column_namesObject (readonly)

Returns the value of attribute column_names.



3
4
5
# File 'lib/dart/core/relation.rb', line 3

def column_names
  @column_names
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



3
4
5
# File 'lib/dart/core/relation.rb', line 3

def table_name
  @table_name
end

Instance Method Details

#add_association(ass) ⇒ Object



38
39
40
# File 'lib/dart/core/relation.rb', line 38

def add_association(ass)
  associations << ass
end

#all_associationsArray<Association>

Returns list of all associations on this relation.

Returns:

  • (Array<Association>)

    list of all associations on this relation



15
16
17
# File 'lib/dart/core/relation.rb', line 15

def all_associations
  associations
end

#child_associationsObject



34
35
36
# File 'lib/dart/core/relation.rb', line 34

def child_associations
  associations.select { |a| a.is_a?(OneToManyAssociation) }
end

#direct_associationsArray<Association>

Returns list of all direct (many_to_one or one_to_many) associations on this relation.

Returns:

  • (Array<Association>)

    list of all direct (many_to_one or one_to_many) associations on this relation



20
21
22
23
# File 'lib/dart/core/relation.rb', line 20

def direct_associations
  # associations - join_associations
  parent_associations + child_associations
end

#join_associationsArray<Association>

Returns list of all join (many_to_many) associations on this relation.

Returns:

  • (Array<Association>)

    list of all join (many_to_many) associations on this relation



26
27
28
# File 'lib/dart/core/relation.rb', line 26

def join_associations
  associations.select { |a| a.is_a?(ManyToManyAssociation) }
end

#parent_associationsObject



30
31
32
# File 'lib/dart/core/relation.rb', line 30

def parent_associations
  associations.select { |a| a.is_a?(ManyToOneAssociation) }
end

#to_sObject



42
43
44
# File 'lib/dart/core/relation.rb', line 42

def to_s
  table_name
end