Rails HABTM关系出现奇怪错误

时间:2015-02-14 09:59:03

标签: ruby-on-rails rails-activerecord has-and-belongs-to-many

我遇到HABTM关系案例的奇怪错误

class Deal < ActiveRecord::Base
  has_and_belongs_to_many :outlets
end

class Outlet < ActiveRecord::Base
 has_and_belongs_to_many :deals
end
当我尝试在交易

中添加商店时,

产生了非常奇怪的错误

@deal.outlets << @outlet
@deal.outlet_ids = [1]

我正在关注

Outlet Load (0.8ms)  SELECT  "outlets".* FROM "outlets"   ORDER BY "outlets"."id" DESC LIMIT 1
   (0.4ms)  BEGIN
PG::UndefinedTable: ERROR:  relation "" does not exist
LINE 5:               AND cons.conrelid = '""'::regclass
                                          ^
:             SELECT attr.attname
            FROM pg_attribute attr
            INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]
            WHERE cons.contype = 'p'
              AND cons.conrelid = '""'::regclass

   (0.1ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "" does not exist
LINE 5:               AND cons.conrelid = '""'::regclass
                                          ^
:             SELECT attr.attname
            FROM pg_attribute attr
            INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]
            WHERE cons.contype = 'p'
              AND cons.conrelid = '""'::regclass

0 个答案:

没有答案