aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-03-27 19:19:27 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-03-27 19:20:21 +0200
commitee4a79da07ef5afd0cf14b56ed32315031428cf1 (patch)
tree1652b952d9b271597f3affff8e4330634e7bf376
parentf6983bdbac0ea0edfc3461cb569799b342124718 (diff)
downloadsonarqube-ee4a79da07ef5afd0cf14b56ed32315031428cf1.tar.gz
sonarqube-ee4a79da07ef5afd0cf14b56ed32315031428cf1.zip
Add activerecord relation between PROJECTS and AUTHORS
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/project.rb39
1 files changed, 20 insertions, 19 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb
index fd185edcc55..016fe99c9ca 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb
@@ -32,6 +32,7 @@ class Project < ActiveRecord::Base
belongs_to :root, :class_name => 'Project', :foreign_key => 'root_id'
belongs_to :copy_resource, :class_name => 'Project', :foreign_key => 'copy_resource_id'
belongs_to :person, :class_name => 'Project', :foreign_key => 'person_id'
+ has_many :authors, :foreign_key => 'person_id', :dependent => :delete_all
def self.by_key(k)
begin
@@ -54,9 +55,9 @@ class Project < ActiveRecord::Base
def root_project
@root_project ||=
- begin
- parent_module(self)
- end
+ begin
+ parent_module(self)
+ end
end
# bottom-up array of projects,
@@ -68,9 +69,9 @@ class Project < ActiveRecord::Base
def resource_link
@resource_link ||=
- begin
- (copy_resource && copy_resource.qualifier==qualifier) ? copy_resource : nil
- end
+ begin
+ (copy_resource && copy_resource.qualifier==qualifier) ? copy_resource : nil
+ end
end
def permanent_resource
@@ -83,13 +84,13 @@ class Project < ActiveRecord::Base
def last_snapshot
@last_snapshot ||=
- begin
- snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => id})
- if snapshot
- snapshot.project=self
- end
- snapshot
+ begin
+ snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => id})
+ if snapshot
+ snapshot.project=self
end
+ snapshot
+ end
end
def events_with_snapshot
@@ -119,13 +120,13 @@ class Project < ActiveRecord::Base
def chart_measures(metric_id)
sql = Project.send(:sanitize_sql, ['select s.created_at as created_at, m.value as value ' +
- ' from project_measures m, snapshots s ' +
- ' where s.id=m.snapshot_id and ' +
- " s.status='%s' and " +
- ' s.project_id=%s and m.metric_id=%s ', Snapshot::STATUS_PROCESSED, self.id, metric_id]) +
- ' and m.rule_id IS NULL and m.rule_priority IS NULL' +
- ' and m.person_id IS NULL' +
- ' order by s.created_at'
+ ' from project_measures m, snapshots s ' +
+ ' where s.id=m.snapshot_id and ' +
+ " s.status='%s' and " +
+ ' s.project_id=%s and m.metric_id=%s ', Snapshot::STATUS_PROCESSED, self.id, metric_id]) +
+ ' and m.rule_id IS NULL and m.rule_priority IS NULL' +
+ ' and m.person_id IS NULL' +
+ ' order by s.created_at'
create_chart_measures(Project.connection.select_all(sql), 'created_at', 'value')
end