我有兩種模式:Show和Deal。空列名同時銷燬對象
class Show < ActiveRecord::Base
has_many :deals, :inverse_of => :show, :dependent => :destroy
...
class Deal < ActiveRecord::Base
belongs_to :show, :inverse_of => :deals
...
當我試圖摧毀顯示我得到這個錯誤:
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
附:我通過向交易表添加主鍵來解決此問題,但我並不真的需要它。所以這個問題仍然是真實的。我可以在沒有ID主鍵的情況下使用依賴關係嗎?
在你的例子中,實體之間的關係是一對一的,但在我的情況下它是一對多的,所以'deal'是正確的 – Donotello