Skip to content

Use 'preload' in export to CSV

Jan Provaznik requested to merge jprovazn-csv into master

What does this MR do?

It assures that associated resources are fetched in a separate query instead of single query.

Why was this MR needed?

If .includes is used then Active Record uses JOIN to fetch associated resources under some circumstances (when also .references is used) this causes problem in combination with GROUP BY statement which is used by label filter and SQL query fails on:

ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "users.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: ..._r25, "issues"."service_desk_reply_to" AS t0_r26, "users"."i...

Use of .preload assures that Active Record always does a separate query to fetch associated resources.

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

#4376 (closed)

Edited by Grzegorz Bizon

Merge request reports