lib/rasti/db/relations/many_to_many.rb in rasti-db-1.4.0 vs lib/rasti/db/relations/many_to_many.rb in rasti-db-1.5.0
- old
+ new
@@ -17,25 +17,25 @@
def qualified_relation_collection_name(schema=nil)
schema.nil? ? Sequel[relation_collection_name] : Sequel[schema][relation_collection_name]
end
- def graph_to(rows, db, schema=nil, relations=[])
+ def fetch_graph(rows, db, schema=nil, selected_attributes=nil, excluded_attributes=nil, relations_graph=nil)
pks = rows.map { |row| row[source_collection_class.primary_key] }
target_collection = target_collection_class.new db, schema
relation_name = qualified_relation_collection_name schema
join_rows = target_collection.dataset
.join(relation_name, target_foreign_key => target_collection_class.primary_key)
.where(Sequel[relation_name][source_foreign_key] => pks)
- .select_all(qualified_target_collection_name(schema))
+ .select_all(target_collection_class.collection_name)
.select_append(Sequel[relation_name][source_foreign_key].as(:source_foreign_key))
.all
- GraphBuilder.graph_to join_rows, relations, target_collection_class, db, schema
+ relations_graph.fetch_graph join_rows if relations_graph
relation_rows = join_rows.each_with_object(Hash.new { |h,k| h[k] = [] }) do |row, hash|
attributes = row.select { |attr,_| target_collection_class.model.attributes.include? attr }
hash[row[:source_foreign_key]] << target_collection_class.model.new(attributes)
end
@@ -43,11 +43,11 @@
rows.each do |row|
row[name] = relation_rows.fetch row[target_collection_class.primary_key], []
end
end
- def join_to(dataset, schema=nil, prefix=nil)
+ def add_join(dataset, schema=nil, prefix=nil)
many_to_many_relation_alias = with_prefix prefix, "#{relation_collection_name}_#{SecureRandom.base64}"
qualified_relation_source = prefix ? Sequel[prefix] : qualified_source_collection_name(schema)
many_to_many_condition = {
@@ -67,10 +67,10 @@
def apply_filter(dataset, schema=nil, primary_keys=[])
relation_name = qualified_relation_collection_name schema
dataset.join(relation_name, source_foreign_key => target_collection_class.primary_key)
.where(Sequel[relation_name][target_foreign_key] => primary_keys)
- .select_all(qualified_source_collection_name(schema))
+ .select_all(source_collection_class.collection_name)
.distinct
end
end
end
\ No newline at end of file