xronos-ch / xronos.rails

Ruby on Rails application powering XRONOS, an open infrastructure for chronometric data from archaeological contexts worldwide
https://xronos.ch
MIT License
4 stars 0 forks source link

Validations on associated records stop records being saved #269

Open joeroe opened 1 year ago

joeroe commented 1 year ago

For example, if you try to update an attribute of a sample that is associated with a context that already has no name, validations will stop you saving it, even though you haven't changed anything. I think this is because of blocks like this (in sample.rb):

  belongs_to :context, optional: true
  accepts_nested_attributes_for :context, :reject_if => proc { |attributes| attributes.all? { |key, value| key == "_destroy" || value.blank? || (value.is_a?(Hash) && value.values.all?(&:blank?)) } }
  validates_associated :context

But I'm unsure what the intended purpose of this is.

joeroe commented 1 year ago

NB. I monkey-patched production to remove this, so I could do some batch cleaning of samples.