diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 9abe6467a74f6b91d5641e679d06548ecac04ee2..ccbbfd2205a64ce64b526e6db37fddcf34677439 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -556,6 +556,9 @@ class DynamicFormField extends VerySimpleModel { 'null' => true, 'constraint' => array('form_id' => 'DynamicForm.id'), ), + 'answers' => array( + 'reverse' => 'DynamicFormEntryAnswer.field', + ), ), ); @@ -864,6 +867,8 @@ class DynamicFormField extends VerySimpleModel { } function delete() { + $values = $this->answers->count(); + // Don't really delete form fields with data as that will screw up the data // model. Instead, just drop the association with the form which // will give the appearance of deletion. Not deleting means that @@ -878,7 +883,7 @@ class DynamicFormField extends VerySimpleModel { $impl->db_cleanup(true); // Short-circuit deletion if the field has data. - if ($impl->hasData()) + if ($impl->hasData() && $values) return $this->save(); // Delete the field for realz