我有两个模型:Show 和 Deal。
class Show < ActiveRecord::Base
has_many :deals, :inverse_of => :show, :dependent => :destroy
...
class Deal < ActiveRecord::Base
belongs_to :show, :inverse_of => :deals
...
当我尝试销毁 Show 时,我收到此错误:
PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: DELETE FROM "deals" WHERE "deals"."" = $1
为什么列名是空的?在 schema.rb 中:
create_table "deals", :id => false, :force => true do |t|
t.integer "discount_id"
t.integer "show_id"
end
create_table "shows", :force => true do |t|
t.integer "movie_id"
t.integer "hall_id"
t.datetime "show_time"
t.integer "city_id"
t.integer "price"
end
外键添加到数据库
CONSTRAINT fk_deals_shows FOREIGN KEY (show_id)
REFERENCES shows (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
PS我通过向交易表添加主键解决了这个问题,但我真的不需要它。所以这个问题仍然是实际的。我可以对没有 id 主键的模型使用依赖项吗?