Papertrail中的自定义表名不能与save一起使用

时间:2016-05-04 18:38:56

标签: ruby-on-rails-4 paper-trail-gem

我正在尝试在PaperTrail配置中使用自定义表名(papertrail_versions)。我有文档中描述的设置:

#user.rb
class User < ActiveRecord::Base
  has_paper_trail class_name: "::PapertrailVersion"
end

#papertrail_version.rb
class PapertrailVersion < PaperTrail::Version
    self.table_name = :papertrail_versions
    self.sequence_name = :papertrail_versions_id_seq
end

当我查找User.last.versions时,所形成的查询会查找表papertrail_versions,但是当我保存一个&#34;脏&#34;用户实例,我得到一个错误:

(0.2ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "versions" does not exist
LINE 5:         WHERE a.attrelid = '"versions"'::regclass
                                    ^
:       SELECT a.attname, format_type(a.atttypid, a.atttypmod),
            pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"versions"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

我在这里做错了什么?

0 个答案:

没有答案