所以我有一个Service
有很多Comment
使用acts_as_commentable_with_threading
gem 的模型。
class Service < ActiveRecord::Base
has_many :comments, dependent: :destroy
end
class Comment < ActiveRecord::Base
# Boilerplate gem generated code
end
这是 gem 生成的模式:
create_table "comments", force: true do |t|
t.integer "commentable_id", default: 0
t.string "commentable_type"
t.string "title"
t.text "body"
t.string "subject"
t.integer "user_id", default: 0, null: false
t.integer "parent_id"
t.integer "lft"
t.integer "rgt"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_score", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
t.integer "cached_weighted_score", default: 0
t.integer "cached_weighted_total", default: 0
t.float "cached_weighted_average", default: 0.0
end
当我尝试访问服务时,Rails 管理员生成了错误的查询。它看到has_many :comments
并跳到它。
http://localhost:5000/admin/service/999
PG::UndefinedColumn: 错误: 列 comments.service_id 不存在 LINE 1: SELECT "comments".* FROM "comments" WHERE "comments"."servi...
我该如何解决这个错误?