Patch #21841
closed
Correctly export collections associated with issues.
Added by Anonymous over 9 years ago.
Updated about 6 years ago.
Description
When you have a plugins that add a 1:m association to issues (say tags) and you want to export the associated entities the CSV and PDF exports give you a ActiveRecord_Associations_CollectionProxy object serialization as the column value.
This patch Fixes the behaviour for all mappable (or collectable if you prefer) objects (see attached before and after exports).
Files
Toshi MARUYAMA wrote:
How about you use #to_a?
http://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-to_a
Where exactly do you suggest I use the to_a method?
Both exports (CSV and PDF) loop trough the available columns of the issue query and format the values for display. There is no place to specify that a certain value is a collection or to inject a transformation.
Rails uses to_a when calling a method from Enumerable (ex: collect) on an AR collection. This patch ensures that it gets called when the appropriate type is given (it could be a plain array or a proxy that resolves to an array).
Codruț Gușoi wrote:
Where exactly do you suggest I use the to_a method?
For example: r13248.
In your patch:
diff --git a/lib/redmine/export/pdf/issues_pdf_helper.rb b/lib/redmine/export/pdf/issues_pdf_helper.rb
index a7a4956..a3293a3 100644
--- a/lib/redmine/export/pdf/issues_pdf_helper.rb
+++ b/lib/redmine/export/pdf/issues_pdf_helper.rb
@@ -360,6 +360,8 @@ module Redmine
format_date(value)
elsif value.is_a?(Time)
format_time(value)
+ elsif value.respond_to?(:collect)
+ value.collect(&:to_s).compact.join(', ')
else
value
end
How about joining value in your plugin?
- Status changed from New to Resolved
Closing this as I am no longer interested in the issue.
- Status changed from Resolved to Closed
Codruț Gușoi wrote:
Closing this as I am no longer interested in the issue.
Thanks.
Also available in: Atom
PDF