From c18b71bf0b9971c0571df95bbf67468264bf7139 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 12 Jan 2012 00:10:23 +0600 Subject: [PATCH] [refs #18] changed refs id to string --- app/models/issue.rb | 6 +++++- .../20120111080234_change_commentable_id.rb | 9 +++++++++ db/schema.rb | 19 +++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20120111080234_change_commentable_id.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index 9ae96f439..04ec41356 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -4,7 +4,11 @@ class Issue < ActiveRecord::Base belongs_to :project belongs_to :user - has_many :comments, :as => :commentable + has_many :comments, :as => :commentable, + :finder_sql => 'SELECT comments.* FROM comments ' + + 'WHERE comments.commentable_id = \'#{self.id}\' ' + + ' AND comments.commentable_type = \'#{self.class.name}\' ' + + 'ORDER BY comments.created_at' has_many :subscribes, :as => :subscribeable validates :title, :body, :project_id, :presence => true diff --git a/db/migrate/20120111080234_change_commentable_id.rb b/db/migrate/20120111080234_change_commentable_id.rb new file mode 100644 index 000000000..60c3c3268 --- /dev/null +++ b/db/migrate/20120111080234_change_commentable_id.rb @@ -0,0 +1,9 @@ +class ChangeCommentableId < ActiveRecord::Migration + def self.up + change_column :comments, :commentable_id, :string + end + + def self.down + change_column :comments, :commentable_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index c4eb51827..a943f2d61 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111228182425) do +ActiveRecord::Schema.define(:version => 20120111080234) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -87,7 +87,7 @@ ActiveRecord::Schema.define(:version => 20111228182425) do end create_table "comments", :force => true do |t| - t.integer "commentable_id" + t.string "commentable_id" t.string "commentable_type" t.integer "user_id" t.text "body" @@ -165,6 +165,13 @@ ActiveRecord::Schema.define(:version => 20111228182425) do add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true + create_table "permissions", :force => true do |t| + t.integer "right_id" + t.integer "role_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "platforms", :force => true do |t| t.string "description" t.string "name" @@ -262,6 +269,14 @@ ActiveRecord::Schema.define(:version => 20111228182425) do t.string "owner_type" end + create_table "rights", :force => true do |t| + t.string "name", :null => false + t.string "controller", :null => false + t.string "action", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "rpms", :force => true do |t| t.string "name", :null => false t.integer "arch_id", :null => false