]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2947 Manually load the right violation for a review
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 21 Nov 2011 17:02:57 +0000 (18:02 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 21 Nov 2011 17:02:57 +0000 (18:02 +0100)
=> the "belongs_to" was causing troubles when running too many
analyses in a small time frame : the source code snippet displayed in
a review detail was not always the last snapshot.

sonar-server/src/main/webapp/WEB-INF/app/models/review.rb

index b639eb90849322dc1e259badfbbecc1da8ea1bbd..09fb4aad33562bf1e02babdcbf775ee28b3b131f 100644 (file)
@@ -24,7 +24,6 @@ class Review < ActiveRecord::Base
   belongs_to :project, :class_name => "Project", :foreign_key => "project_id"
   has_many :review_comments, :order => "created_at", :dependent => :destroy
   alias_attribute :comments, :review_comments
-  belongs_to :rule_failure, :foreign_key => 'rule_failure_permanent_id', :primary_key => 'permanent_id'
   
   validates_presence_of :user, :message => "can't be empty"
   validates_presence_of :status, :message => "can't be empty"
@@ -46,6 +45,15 @@ class Review < ActiveRecord::Base
         rule_failure ? rule_failure.rule : nil
       end
   end
+  
+  def rule_failure
+    @rule_failure ||=
+      begin
+        # We need to manually run this DB request as the real relation Reviews-RuleFailures is 1:n but we want only 1 violation
+        # (more than 1 violation can have the same "permanent_id" when several analyses are run in a small time frame)
+        RuleFailure.find(:last, :conditions => {:permanent_id => rule_failure_permanent_id}, :order => 'id asc')
+      end
+  end