I was wondering if there is a way to compare old and new values in a validator within an entity prior to a flush.
I have a Server
entity which renders to a
Previous answers are perfectly valid, and may fit your use case.
For "simple" use case, it may fill heavy though. In the case of an entity editable through (only) a form, you can simply add the constraint on the FormBuilder:
add('fooField', IntegerType::class, [
'constraints' => [
new GreaterThanOrEqual(['value' => $builder->getData()->getFooField()])
]
])
;
}
}
This is valid for any Symfony 2+ version.