Skip to content

Bug: is_unique validation rule with model->save() fails #2906

Description

@nicojmb

Describe the bug

Executing $model->save($data);

if i add a validationRule in model:

protected $validationRules = [
      'name'        => "required|is_unique[myTable.name,name,{name}]"
];

The system permits add same name on insert and on update (both calling with save() method).

if i add this rule:

protected $validationRules = [
      'name'        => "required|is_unique[myTable.name]"
];

The system fails on insert new record thats exists in database but on update show error when name not change.

CodeIgniter 4 version
4.0.2

Affected module(s)
Codeigniter Model.

Expected behavior, and steps to reproduce if appropriate
Executin save() method:
if is new and name exists, show error:
if update and if name exists, show error but if is the same record, continue.

Context

  • OS: [e.g. Windows 99]
  • Web server [e.g. Apache 1.2.3]
  • PHP version [e.g. 6.5.4]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions