1
おはようございます、オーバーフロー、参照されているすべてのテーブルからレコードを削除するにはどうすればよいですか?
モデルの関連付けには小さな問題があります。私は、これらのモデルの関連を持っている: categorization_id
、exhibit_id
とcategory_id
:
class Categorization < ActiveRecord::Base
belongs_to :exhibit
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :categorizations
has_many :exhibits, :through => :categorizations
acts_as_indexed :fields => [:title]
validates :title, :presence => true, :uniqueness => true
end
class Exhibit < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations, :source => :category
acts_as_indexed :fields => [:title, :bulb]
validates :title, :presence => true, :uniqueness => true
belongs_to :foto, :class_name => 'Image'
end
だから、基本的にCategorization
は、これらの列(省略日付/タイムスタンプ)で終わります。
私の問題は、Exhibitを削除すると、分類テーブルの参照が削除されないため、私のビューでDBエラーが発生するということです。展覧会をどのカテゴリからも割り当て解除してから、安全に削除する必要があります。または、私がrails console
を与えたときに削除したExhibit Iが削除されているとします()。Categorization.find_by_exhibit_id(1).destroy
ありがとうございました!
を...そして、我々は勝者を持っています!ありがとう、束縛のように働いたキャスパー.. – Cacofonix