Class: Dart::Relation
- Inherits:
-
Object
- Object
- Dart::Relation
- Defined in:
- lib/dart/core/relation.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#column_names ⇒ Object
readonly
Returns the value of attribute column_names.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #add_association(ass) ⇒ Object
-
#all_associations ⇒ Array<Association>
List of all associations on this relation.
- #child_associations ⇒ Object
-
#direct_associations ⇒ Array<Association>
List of all direct (many_to_one or one_to_many) associations on this relation.
-
#initialize(table, columns) ⇒ Relation
constructor
A new instance of Relation.
-
#join_associations ⇒ Array<Association>
List of all join (many_to_many) associations on this relation.
- #parent_associations ⇒ Object
- #to_s ⇒ Object
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_names ⇒ Object (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_name ⇒ Object (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_associations ⇒ Array<Association>
Returns list of all associations on this relation.
15 16 17 |
# File 'lib/dart/core/relation.rb', line 15 def all_associations associations end |
#child_associations ⇒ Object
34 35 36 |
# File 'lib/dart/core/relation.rb', line 34 def child_associations associations.select { |a| a.is_a?(OneToManyAssociation) } end |
#direct_associations ⇒ Array<Association>
Returns 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_associations ⇒ Array<Association>
Returns 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_associations ⇒ Object
30 31 32 |
# File 'lib/dart/core/relation.rb', line 30 def parent_associations associations.select { |a| a.is_a?(ManyToOneAssociation) } end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/dart/core/relation.rb', line 42 def to_s table_name end |