lib/rasti/db/relations/many_to_one.rb in rasti-db-4.1.1 vs lib/rasti/db/relations/many_to_one.rb in rasti-db-4.2.0
- old
+ new
@@ -5,18 +5,22 @@
def foreign_key
@foreign_key ||= options[:foreign_key] || target_collection_class.foreign_key
end
- def fetch_graph(environment, rows, selected_attributes=nil, excluded_attributes=nil, relations_graph=nil)
+ def fetch_graph(environment, rows, selected_attributes=nil, excluded_attributes=nil, queries=nil, relations_graph=nil)
fks = rows.map { |row| row[foreign_key] }.uniq
target_collection = target_collection_class.new environment
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 = query.exclude_attributes(*excluded_attributes) unless excluded_attributes.nil?
+ query = query.select_attributes(*selected_attributes) unless selected_attributes.nil?
+
+ query = queries.inject(query) { |new_query, sub_query| new_query.send(sub_query) } unless queries.nil?
+
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
@@ -45,6 +49,6 @@
end
end
end
end
-end
\ No newline at end of file
+end