0

I am having strange error with following case of HABTM relationship

class Deal < ActiveRecord::Base
  has_and_belongs_to_many :outlets
end

class Outlet < ActiveRecord::Base
 has_and_belongs_to_many :deals
end

produced very strange error when I try to add outlets in deal

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

I am getting following

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
Lazarus Lazaridis
  • 5,803
  • 2
  • 21
  • 35
Loken Makwana
  • 3,788
  • 2
  • 21
  • 14

0 Answers0