lib/rasti/db/relations/base.rb in rasti-db-1.5.0 vs lib/rasti/db/relations/base.rb in rasti-db-2.0.0

- old
+ new

@@ -31,27 +31,41 @@ def one_to_one? self.class == OneToOne end - def join_relation_name(prefix) - with_prefix prefix, name + def from_one? + one_to_one? || one_to_many? end - private + def from_many? + many_to_one? || many_to_many? + end - attr_reader :options + def to_one? + one_to_one? || many_to_one? + end - def qualified_source_collection_name(schema=nil) - schema.nil? ? Sequel[source_collection_class.collection_name] : Sequel[schema][source_collection_class.collection_name] + def to_many? + one_to_many? || many_to_many? end - def qualified_target_collection_name(schema=nil) - schema.nil? ? Sequel[target_collection_class.collection_name] : Sequel[schema][target_collection_class.collection_name] + def join_relation_name(prefix) + with_prefix prefix, name end + private + + attr_reader :options + def with_prefix(prefix, name) [prefix, name].compact.join('__').to_sym + end + + 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 end end end \ No newline at end of file