class Rasti::DB::Relations::Base
Attributes
name[R]
options[R]
source_collection_class[R]
Public Class Methods
new(name, source_collection_class, options={})
click to toggle source
# File lib/rasti/db/relations/base.rb, line 10 def initialize(name, source_collection_class, options={}) @name = name @source_collection_class = source_collection_class @options = options end
Public Instance Methods
from_many?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 40 def from_many? many_to_one? || many_to_many? end
from_one?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 36 def from_one? one_to_one? || one_to_many? end
join_relation_name(prefix)
click to toggle source
# File lib/rasti/db/relations/base.rb, line 52 def join_relation_name(prefix) with_prefix prefix, name end
many_to_many?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 28 def many_to_many? self.class == ManyToMany end
many_to_one?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 24 def many_to_one? self.class == ManyToOne end
one_to_many?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 20 def one_to_many? self.class == OneToMany end
one_to_one?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 32 def one_to_one? self.class == OneToOne end
target_collection_class()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 16 def target_collection_class @target_collection_class ||= options[:collection].is_a?(Class) ? options[:collection] : Consty.get(options[:collection] || camelize(pluralize(name)), source_collection_class) end
to_many?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 48 def to_many? one_to_many? || many_to_many? end
to_one?()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 44 def to_one? one_to_one? || many_to_one? end
Private Instance Methods
validate_join!()
click to toggle source
# File lib/rasti/db/relations/base.rb, line 64 def validate_join! if source_collection_class.data_source_name != target_collection_class.data_source_name raise "Invalid join of multiple data sources: #{source_collection_class.data_source_name}.#{source_collection_class.collection_name} > #{target_collection_class.data_source_name}.#{target_collection_class.collection_name}" end end
with_prefix(prefix, name)
click to toggle source
# File lib/rasti/db/relations/base.rb, line 60 def with_prefix(prefix, name) [prefix, name].compact.join('__').to_sym end