vendredi 9 mars 2018

Rails - Active Record validations and mark_for_destruction

I'm running on Rails 3.2.22.5 and I can't find any documentation that states whether or not child objects (that have mark_for_destruction set to true) will still have Active Record validations run against them.

Example:

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!

I would expect the validates_presence_of to fail, since the child is marked_for_destruction. However, I have seen this validation pass in has_and_belongs_to_many relationships.

This was apparently a bug in Rails at one point, but I am not clear on what the expectation actually is since it's not documented. https://github.com/rails/rails/issues/6812

Aucun commentaire:

Enregistrer un commentaire