有些物体拒绝被破坏(铁轨)
我正在运行一个 rake 任务来销毁所有“课程”对象:
task :destroy_all_classes => :environment do
Course.all.each do |c|
c.destroy
end
end
这会销毁大部分课程,但还剩下 12 个课程(总共 40 个以上)。什么可能阻止我删除它们?
如果我尝试通过控制台手动删除每门课程,我会得到以下信息:
ruby-1.9.2-p290 :030 > Course.find(1).destroy
=> false
I'm running a rake task to destroy all of my "course" objects:
task :destroy_all_classes => :environment do
Course.all.each do |c|
c.destroy
end
end
This destroys most of the courses, but 12 remain (out of 40+). What might be preventing me from deleting them?
If I try deleting each course manually, through the console, I get this:
ruby-1.9.2-p290 :030 > Course.find(1).destroy
=> false
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
启用级联销毁。
当然与另一个模型至少有一个“有很多”或“有一个”关系。像
make it
这样的东西你也可以使用
祝你好运!
Enable cascade destroy.
Course have at lest one "has many"or "has one" relation with another model.Something like
make it
You can also use
Best of luck !!!