summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-03-15 22:11:02 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-03-15 22:11:02 +0000
commite6f58e4dcc2f7552109da139857a19b81c6f1fe1 (patch)
treeb2b7aee365335b13fb3f8d2ebac44b518cbbcd71 /app/models
parent192b9008bdc5590a041166635eb1aecae78df992 (diff)
downloadredmine-e6f58e4dcc2f7552109da139857a19b81c6f1fe1.tar.gz
redmine-e6f58e4dcc2f7552109da139857a19b81c6f1fe1.zip
fixed #9308 table_name pre/suffix support
git-svn-id: http://redmine.rubyforge.org/svn/trunk@337 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/issue_custom_field.rb4
-rw-r--r--app/models/news.rb2
-rw-r--r--app/models/project.rb23
-rw-r--r--app/models/query.rb32
-rw-r--r--app/models/tracker.rb2
5 files changed, 30 insertions, 33 deletions
diff --git a/app/models/issue_custom_field.rb b/app/models/issue_custom_field.rb
index 7759c9059..d087768a4 100644
--- a/app/models/issue_custom_field.rb
+++ b/app/models/issue_custom_field.rb
@@ -16,8 +16,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueCustomField < CustomField
- has_and_belongs_to_many :projects, :join_table => "custom_fields_projects", :foreign_key => "custom_field_id"
- has_and_belongs_to_many :trackers, :join_table => "custom_fields_trackers", :foreign_key => "custom_field_id"
+ has_and_belongs_to_many :projects, :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :foreign_key => "custom_field_id"
+ has_and_belongs_to_many :trackers, :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :foreign_key => "custom_field_id"
has_many :issues, :through => :issue_custom_values
def type_name
diff --git a/app/models/news.rb b/app/models/news.rb
index 848517302..cd130e96d 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -24,6 +24,6 @@ class News < ActiveRecord::Base
# returns latest news for projects visible by user
def self.latest(user=nil, count=5)
- find(:all, :limit => count, :conditions => Project.visible_by(user), :include => [ :author, :project ], :order => "news.created_on DESC")
+ find(:all, :limit => count, :conditions => Project.visible_by(user), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 3cf5a816a..3579921b7 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -16,18 +16,18 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Project < ActiveRecord::Base
- has_many :versions, :dependent => :destroy, :order => "versions.effective_date DESC, versions.name DESC"
- has_many :members, :dependent => :delete_all, :include => :user, :conditions => "users.status=#{User::STATUS_ACTIVE}"
+ has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
+ has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
has_many :users, :through => :members
has_many :custom_values, :dependent => :delete_all, :as => :customized
- has_many :issues, :dependent => :destroy, :order => "issues.created_on DESC", :include => [:status, :tracker]
+ has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
has_many :queries, :dependent => :delete_all
has_many :documents, :dependent => :destroy
has_many :news, :dependent => :delete_all, :include => :author
- has_many :issue_categories, :dependent => :delete_all, :order => "issue_categories.name"
+ has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
has_one :repository, :dependent => :destroy
has_one :wiki, :dependent => :destroy
- has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => 'custom_fields_projects', :association_foreign_key => 'custom_field_id'
+ has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
acts_as_tree :order => "name", :counter_cache => true
validates_presence_of :name, :description
@@ -39,28 +39,25 @@ class Project < ActiveRecord::Base
# returns latest created projects
# non public projects will be returned only if user is a member of those
def self.latest(user=nil, count=5)
- find(:all, :limit => count, :conditions => visible_by(user), :order => "projects.created_on DESC")
+ find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
end
def self.visible_by(user=nil)
if user && !user.memberships.empty?
- return ["projects.is_public = ? or projects.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true]
+ return ["#{Project.table_name}.is_public = ? or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true]
else
- return ["projects.is_public = ?", true]
+ return ["#{Project.table_name}.is_public = ?", true]
end
end
# Returns an array of all custom fields enabled for project issues
# (explictly associated custom fields and custom fields enabled for all projects)
def custom_fields_for_issues(tracker)
- tracker.custom_fields.find(:all, :include => :projects,
- :conditions => ["is_for_all=? or project_id=?", true, self.id])
- #(CustomField.for_all + custom_fields).uniq
+ all_custom_fields.select {|c| tracker.custom_fields.include? c }
end
def all_custom_fields
- @all_custom_fields ||= IssueCustomField.find(:all, :include => :projects,
- :conditions => ["is_for_all=? or project_id=?", true, self.id])
+ @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq
end
protected
diff --git a/app/models/query.rb b/app/models/query.rb
index b6c9b680a..fbf48927a 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -124,42 +124,42 @@ class Query < ActiveRecord::Base
def statement
sql = "1=1"
- sql << " AND issues.project_id=%d" % project.id if project
+ sql << " AND #{Issue.table_name}.project_id=%d" % project.id if project
filters.each_key do |field|
v = values_for field
next unless v and !v.empty?
sql = sql + " AND " unless sql.empty?
case operator_for field
when "="
- sql = sql + "issues.#{field} IN (" + v.each(&:to_i).join(",") + ")"
+ sql = sql + "#{Issue.table_name}.#{field} IN (" + v.each(&:to_i).join(",") + ")"
when "!"
- sql = sql + "issues.#{field} NOT IN (" + v.each(&:to_i).join(",") + ")"
+ sql = sql + "#{Issue.table_name}.#{field} NOT IN (" + v.each(&:to_i).join(",") + ")"
when "!*"
- sql = sql + "issues.#{field} IS NULL"
+ sql = sql + "#{Issue.table_name}.#{field} IS NULL"
when "*"
- sql = sql + "issues.#{field} IS NOT NULL"
+ sql = sql + "#{Issue.table_name}.#{field} IS NOT NULL"
when "o"
- sql = sql + "issue_statuses.is_closed=#{connection.quoted_false}" if field == "status_id"
+ sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
when "c"
- sql = sql + "issue_statuses.is_closed=#{connection.quoted_true}" if field == "status_id"
+ sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
when ">t-"
- sql = sql + "issues.#{field} >= '%s'" % connection.quoted_date(Date.today - v.first.to_i)
+ sql = sql + "#{Issue.table_name}.#{field} >= '%s'" % connection.quoted_date(Date.today - v.first.to_i)
when "<t-"
- sql = sql + "issues.#{field} <= '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{Issue.table_name}.#{field} <= '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
when "t-"
- sql = sql + "issues.#{field} = '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{Issue.table_name}.#{field} = '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
when ">t+"
- sql = sql + "issues.#{field} >= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{Issue.table_name}.#{field} >= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
when "<t+"
- sql = sql + "issues.#{field} <= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{Issue.table_name}.#{field} <= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
when "t+"
- sql = sql + "issues.#{field} = '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{Issue.table_name}.#{field} = '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
when "t"
- sql = sql + "issues.#{field} = '%s'" % connection.quoted_date(Date.today)
+ sql = sql + "#{Issue.table_name}.#{field} = '%s'" % connection.quoted_date(Date.today)
when "~"
- sql = sql + "issues.#{field} LIKE '%#{connection.quote_string(v.first)}%'"
+ sql = sql + "#{Issue.table_name}.#{field} LIKE '%#{connection.quote_string(v.first)}%'"
when "!~"
- sql = sql + "issues.#{field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
+ sql = sql + "#{Issue.table_name}.#{field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
end
end if filters and valid?
sql
diff --git a/app/models/tracker.rb b/app/models/tracker.rb
index 51ae73d1c..14ac904c3 100644
--- a/app/models/tracker.rb
+++ b/app/models/tracker.rb
@@ -19,7 +19,7 @@ class Tracker < ActiveRecord::Base
before_destroy :check_integrity
has_many :issues
has_many :workflows, :dependent => :delete_all
- has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => 'custom_fields_trackers', :association_foreign_key => 'custom_field_id'
+ has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
acts_as_list
validates_presence_of :name