From: Jean-Philippe Lang Date: Wed, 22 Oct 2014 18:41:03 +0000 (+0000) Subject: Removed unneeded :foreign_key option on belongs_to associations. X-Git-Tag: 3.0.0~485 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=498a34403ad3f15dee2067e9d8998675255010ce;p=redmine.git Removed unneeded :foreign_key option on belongs_to associations. git-svn-id: http://svn.redmine.org/redmine/trunk@13484 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 9d7e03247..2af10663e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -20,7 +20,7 @@ require "fileutils" class Attachment < ActiveRecord::Base belongs_to :container, :polymorphic => true - belongs_to :author, :class_name => "User", :foreign_key => "author_id" + belongs_to :author, :class_name => "User" validates_presence_of :filename, :author validates_length_of :filename, :maximum => 255 diff --git a/app/models/board.rb b/app/models/board.rb index 2cbeb0a8a..4a9984a03 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -20,7 +20,7 @@ class Board < ActiveRecord::Base belongs_to :project has_many :topics, lambda {where("#{Message.table_name}.parent_id IS NULL").order("#{Message.table_name}.created_on DESC")}, :class_name => 'Message' has_many :messages, lambda {order("#{Message.table_name}.created_on DESC")}, :dependent => :destroy - belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id + belongs_to :last_message, :class_name => 'Message' acts_as_tree :dependent => :nullify acts_as_list :scope => '(project_id = #{project_id} AND parent_id #{parent_id ? "= #{parent_id}" : "IS NULL"})' acts_as_watchable diff --git a/app/models/comment.rb b/app/models/comment.rb index 9893ad664..abe755018 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -18,7 +18,7 @@ class Comment < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :commented, :polymorphic => true, :counter_cache => true - belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + belongs_to :author, :class_name => 'User' validates_presence_of :commented, :author, :comments attr_protected :id diff --git a/app/models/document.rb b/app/models/document.rb index c195f64ca..00530131a 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -18,7 +18,7 @@ class Document < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project - belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" + belongs_to :category, :class_name => "DocumentCategory" acts_as_attachable :delete_permission => :delete_documents acts_as_searchable :columns => ['title', "#{table_name}.description"], diff --git a/app/models/issue.rb b/app/models/issue.rb index bb45a6f58..34a49be0d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -22,12 +22,12 @@ class Issue < ActiveRecord::Base belongs_to :project belongs_to :tracker - belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' - belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' - belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id' - belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id' - belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id' - belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id' + belongs_to :status, :class_name => 'IssueStatus' + belongs_to :author, :class_name => 'User' + belongs_to :assigned_to, :class_name => 'Principal' + belongs_to :fixed_version, :class_name => 'Version' + belongs_to :priority, :class_name => 'IssuePriority' + belongs_to :category, :class_name => 'IssueCategory' has_many :journals, :as => :journalized, :dependent => :destroy has_many :visible_journals, diff --git a/app/models/issue_category.rb b/app/models/issue_category.rb index e5e508861..4fda288b8 100644 --- a/app/models/issue_category.rb +++ b/app/models/issue_category.rb @@ -18,7 +18,7 @@ class IssueCategory < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project - belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id' + belongs_to :assigned_to, :class_name => 'Principal' has_many :issues, :foreign_key => 'category_id', :dependent => :nullify validates_presence_of :name diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb index 1ba50edc1..2659bb2e7 100644 --- a/app/models/issue_relation.rb +++ b/app/models/issue_relation.rb @@ -30,8 +30,8 @@ class IssueRelation < ActiveRecord::Base end end - belongs_to :issue_from, :class_name => 'Issue', :foreign_key => 'issue_from_id' - belongs_to :issue_to, :class_name => 'Issue', :foreign_key => 'issue_to_id' + belongs_to :issue_from, :class_name => 'Issue' + belongs_to :issue_to, :class_name => 'Issue' TYPE_RELATES = "relates" TYPE_DUPLICATES = "duplicates" diff --git a/app/models/message.rb b/app/models/message.rb index 028a3eb55..a5540d953 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,10 +18,10 @@ class Message < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :board - belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + belongs_to :author, :class_name => 'User' acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" acts_as_attachable - belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' + belongs_to :last_reply, :class_name => 'Message' attr_protected :id acts_as_searchable :columns => ['subject', 'content'], diff --git a/app/models/news.rb b/app/models/news.rb index baaa92fba..59411bd44 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -18,7 +18,7 @@ class News < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project - belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + belongs_to :author, :class_name => 'User' has_many :comments, lambda {order("created_on")}, :as => :commented, :dependent => :delete_all validates_presence_of :title, :description diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 8738668cc..80112308a 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -22,7 +22,7 @@ class TimeEntry < ActiveRecord::Base belongs_to :project belongs_to :issue belongs_to :user - belongs_to :activity, :class_name => 'TimeEntryActivity', :foreign_key => 'activity_id' + belongs_to :activity, :class_name => 'TimeEntryActivity' attr_protected :user_id, :tyear, :tmonth, :tweek diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index 3eac92688..9377ccfc2 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -19,8 +19,8 @@ require 'zlib' class WikiContent < ActiveRecord::Base self.locking_column = 'version' - belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id' - belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + belongs_to :page, :class_name => 'WikiPage' + belongs_to :author, :class_name => 'User' validates_presence_of :text validates_length_of :comments, :maximum => 255, :allow_nil => true attr_protected :id @@ -54,8 +54,8 @@ class WikiContent < ActiveRecord::Base end class Version - belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' - belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' + belongs_to :page, :class_name => '::WikiPage' + belongs_to :author, :class_name => '::User' attr_protected :data acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, diff --git a/app/models/workflow_rule.rb b/app/models/workflow_rule.rb index 3d1b75bd0..0cd837d7c 100644 --- a/app/models/workflow_rule.rb +++ b/app/models/workflow_rule.rb @@ -20,8 +20,8 @@ class WorkflowRule < ActiveRecord::Base belongs_to :role belongs_to :tracker - belongs_to :old_status, :class_name => 'IssueStatus', :foreign_key => 'old_status_id' - belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id' + belongs_to :old_status, :class_name => 'IssueStatus' + belongs_to :new_status, :class_name => 'IssueStatus' validates_presence_of :role, :tracker, :old_status attr_protected :id