Skip to content

Model validation: Unique rule #2

@ghost

Description

So, i've been using this plugin and I found an issue when trying to implement the isUnique rule validation from CakePHP itself. The validation rule can't find any records because the behavior filters it, as it really should, but, since the query can't find deleted records when validating, it can't assegure the unique rule for the field too.

To solve this, we can override the validation method directly from the SoftDeletableModel class:

class SoftDeletableModel extends Model
{
    [...]

    public function isUnique($fields, $or = true) {
        // implement logic here
    }

    [...]
}

I can make a PR if you think it's fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions