Rails - Active Record验证和mark_for_destruction

时间:2018-03-09 14:50:31

标签: ruby-on-rails ruby-on-rails-3 activerecord ruby-on-rails-3.2 rails-activerecord

我在Rails 3.2.22.5上运行,我找不到任何文档来说明子对象(mark_for_destruction设置为true)是否仍然会对它们运行Active Record验证。< / p>

示例:

class Parent < ActiveRecord::Base
  has_many :children
  validates_presence_of :children

class Child < ActiveRecord::Base
  belongs_to :parent


 parent = Parent.new
 parent.children << Child.new
 parent.children.first.mark_for_destruction
 parent.save!

我希望validates_presence_of失败,因为孩子是marked_for_destruction。但是,我已经在has_and_belongs_to_many关系中看到了此验证传递。

这显然是Rails中的一个错误,但我不清楚实际的期望是什么,因为它没有记录。 https://github.com/rails/rails/issues/6812

0 个答案:

没有答案