我有一个与Trainer
和许多Facilities
相关联的课程ServiceClasses
。我只想在设施和null
表中制作参考service_classes
,当教练记录被销毁时。
每当我尝试trainer.destroy
时,它会向我显示错误,就像我在屏幕截图中提到的那样。
我也尝试过回调来制作参考null
before_destroy
,但它对我也不起作用。
如果有人可以指导我,请提前感谢,这已经花了我很多时间。
师:
class Trainer < ActiveRecord::Base
belongs_to :user
has_many :service_classes,dependent: :nullify
has_many :facilities,dependent: :nullify
end
服务类:
class ServiceClass < ActiveRecord::Base
acts_as_paranoid
mount_uploader :image, EventUploader
belongs_to :trainer
end
设施类:
class Facility < ActiveRecord::Base
acts_as_paranoid
belongs_to :user
belongs_to :facility_category
has_many :facility_prices
has_many :facility_details
belongs_to :trainer
end
架构:
create_table "service_classes", force: :cascade do |t|
t.string "name"
t.text "description"
t.string "image"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "deleted_at"
t.integer "trainer_id"
end
add_index "service_classes", ["deleted_at"], name: "index_service_classes_on_deleted_at", using: :btree
add_index "service_classes", ["trainer_id"], name: "index_service_classes_on_trainer_id", using: :btree
create_table "facilities", force: :cascade do |t|
t.string "name"
t.integer "user_id"
t.integer "facility_category_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "deleted_at"
t.integer "trainer_id"
end
add_index "facilities", ["deleted_at"], name: "index_facilities_on_deleted_at", using: :btree
add_index "facilities", ["trainer_id"], name: "index_facilities_on_trainer_id", using: :btree