Patch #21841
closed
Correctly export collections associated with issues.
0%
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
Updated by Toshi MARUYAMA about 9 years ago
How about you use #to_a?
http://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-to_a
Updated by Anonymous about 9 years ago
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).
Updated by Toshi MARUYAMA about 9 years ago
Updated by Toshi MARUYAMA about 9 years ago
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?
Updated by Anonymous about 6 years ago
- Status changed from New to Resolved
Closing this as I am no longer interested in the issue.
Updated by Marius BĂLTEANU about 6 years ago
- Status changed from Resolved to Closed
Codruț Gușoi wrote:
Closing this as I am no longer interested in the issue.
Thanks.