ruby - Datamapper:报告为什么我不能销毁记录

标签 ruby datamapper ruby-datamapper

我正在使用数据映射器和 dm-contraints 设置我的数据库模型。我有两个具有多对多关系的模型,但当我试图破坏其中一个时,我得到的唯一消息是 false

是否可以让 datamapper 给我更多反馈,到底是哪种关系导致了问题?

最佳答案

使用数据映射器 1.2.1:

def why_you_no_destroy? model
  preventing = []
  model.send(:relationships).each do |relationship|
    next unless relationship.respond_to?(:enforce_destroy_constraint)
    preventing << relationship.name unless relationship.enforce_destroy_constraint(model)
  end
  preventing
end

关于ruby - Datamapper:报告为什么我不能销毁记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14233496/

相关文章:

ruby-on-rails - ActiveRecord::Base before_validation with conditional not triggered

python - 转字符串方法的 Ruby 版本

ruby-on-rails - Ruby 默认是线程安全的吗?

php - 如何验证数据映射器模式中的唯一性?

ruby - 未定义的方法 auto_upgrade!将 Sinatra/DataMapper 应用程序推送到 Heroku 时

ruby - 提取域名中的个别现有词

ruby - 使用 Sinatra 制作日历

mysql - Ruby 应用程序中的 DataMapper DB 池

mysql - DataMapper 枚举字段在保存或更新时不会保留