]> source.dussan.org Git - redmine.git/commitdiff
The result of Attachment.latest_attach is unstable if attachments have the same times...
authorGo MAEDA <maeda@farend.jp>
Wed, 7 Apr 2021 05:30:01 +0000 (05:30 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 7 Apr 2021 05:30:01 +0000 (05:30 +0000)
Patch by Pavel Rosický.

git-svn-id: http://svn.redmine.org/redmine/trunk@20923 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb

index 620ea89ef870253f60d7b9dda3108d2368577167..241ed0d707b7374957dccde1c35ace3619be1572 100644 (file)
@@ -370,7 +370,7 @@ class Attachment < ActiveRecord::Base
   def self.latest_attach(attachments, filename)
     return unless filename.valid_encoding?
 
-    attachments.sort_by(&:created_on).reverse.detect do |att|
+    attachments.sort_by{|attachment| [attachment.created_on, attachment.id]}.reverse.detect do |att|
       filename.casecmp?(att.filename)
     end
   end