always include relevant columns

- caller does not need to do it anymore
- caller is still allowed to do it, because it can also add own conditions...
pull/3338/head
Jan Sandbrink 9 years ago
parent 7552fab9ce
commit 2a65240e52
  1. 3
      app/controllers/api/experimental/work_packages_controller.rb
  2. 3
      app/controllers/work_packages/calendars_controller.rb
  3. 3
      app/controllers/work_packages_controller.rb
  4. 5
      app/models/query/results.rb

@ -97,8 +97,7 @@ module Api
def current_work_packages
initialize_sort
results = @query.results include: includes_for_columns(@query.involved_columns),
order: sort_clause
results = @query.results order: sort_clause
work_packages = results.work_packages
.page(page_param)

@ -50,8 +50,7 @@ class WorkPackages::CalendarsController < ApplicationController
retrieve_query
@query.group_by = nil
if @query.valid?
events = @query.results(include: [:type, :assigned_to, :priority],
conditions: ["((#{WorkPackage.table_name}.start_date BETWEEN ? AND ?) OR (#{WorkPackage.table_name}.due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
events = @query.results(conditions: ["((#{WorkPackage.table_name}.start_date BETWEEN ? AND ?) OR (#{WorkPackage.table_name}.due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
).work_packages
events += @query.results(conditions: ["#{Version.table_name}.effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]).versions

@ -446,8 +446,7 @@ class WorkPackagesController < ApplicationController
sort_init(@query.sort_criteria.empty? ? [DEFAULT_SORT_ORDER] : @query.sort_criteria)
sort_update(@query.sortable_columns)
@results = @query.results(include: [:assigned_to, :type, :priority, :category, :fixed_version],
order: sort_clause)
@results = @query.results(order: sort_clause)
@work_packages = if @query.valid?
@results.work_packages.page(page_param)
.per_page(per_page_param)

@ -80,6 +80,7 @@ class ::Query::Results
def work_packages
WorkPackage.where(::Query.merge_conditions(query.statement, options[:conditions]))
.includes([:status, :project] + (options[:include] || []).uniq)
.includes(includes_for_columns(query.involved_columns))
.joins((query.group_by_column ? query.group_by_column.join : nil))
.order(order_option)
.references(:projects)
@ -90,9 +91,7 @@ class ::Query::Results
# If there is a reason: This is a somewhat DRY way of using the sort criteria.
# If there is no reason: The :work_package method can die over time and be replaced by this one.
def sorted_work_packages
work_packages
.includes(includes_for_columns(query.involved_columns))
.order(query.sort_criteria_sql)
work_packages.order(query.sort_criteria_sql)
end
def versions

Loading…
Cancel
Save