私は2つのモデルを持っています。オブジェクトを破棄している間に空の列名
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
P.S.に追加しました私はこの問題を取引テーブルにプライマリキーを追加することで解決しましたが、実際には必要ありません。だから質問はまだ実際です。 IDの主キーを持たないモデルに依存関係を使用できますか?
belongs_to :show, :inverse_of => :deal
私はそれをサポートしていないcompositekeysレールによると
あなたの例では、エンティティ間の関係は1対1ですが、私の場合は1対多ですから、 'deals'は正しいです – Donotello