lib/rasti/db/relations/many_to_one.rb in rasti-db-1.4.0 vs lib/rasti/db/relations/many_to_one.rb in rasti-db-1.5.0
- old
+ new
@@ -5,26 +5,29 @@
def foreign_key
@foreign_key ||= options[:foreign_key] || target_collection_class.foreign_key
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)
fks = rows.map { |row| row[foreign_key] }.uniq
target_collection = target_collection_class.new db, schema
- relation_rows = target_collection.where(source_collection_class.primary_key => fks)
- .graph(*relations)
- .each_with_object({}) do |row, hash|
- hash[row.public_send(source_collection_class.primary_key)] = row
- end
+ query = target_collection.where(source_collection_class.primary_key => fks)
+ query = query.exclude_attributes(*excluded_attributes) if excluded_attributes
+ query = query.select_attributes(*selected_attributes) if selected_attributes
+ query = relations_graph.apply_to query if relations_graph
+
+ relation_rows = query.each_with_object({}) do |row, hash|
+ hash[row.public_send(source_collection_class.primary_key)] = row
+ end
rows.each do |row|
row[name] = relation_rows[row[foreign_key]]
end
end
- def join_to(dataset, schema=nil, prefix=nil)
+ def add_join(dataset, schema=nil, prefix=nil)
relation_alias = join_relation_name prefix
qualified_relation_source = prefix ? Sequel[prefix] : qualified_source_collection_name(schema)
relation_condition = {
\ No newline at end of file