We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Uniqueness validation when using soft delete

Hi,

Is there a way of getting Uniqueness to accept a way of ignoring records where deleted is not null?
I've seen someone mention an except option but couldn't find any docs.

Or is the alternative to use Callback in 3.1.1?

Thanks, Gary

Uniqueness validation is best to go:

$validation->add('someField', new Uniqueness([
    'message' => 'field is not unique',
    'except' => [
        'deleted' => 1
    ]
]);
edited Mar '17

Ok cool, will try later.
Any chance of getting this documented anywhere?

Also, my deleted column is a timestamp so need to specifically check for if is not null, how would that work?

Well right now you can provide only value or array of values which can be except. I would just suggest changing your schema to have deleted and deleted_at for now and you could create some issue on github, though idk really how it should be done, maybe using seperated option like exceptNull and exceptNotNull which will accept field name or array of fields? This is just an idea, you should create issue on github and if you have some other idea then propose it there.