cphalcon: [BUG] Uniqueness validator incorrectly fails validation on update
With the following model $id is the primary key and $name must be unique within $project_id
use Phalcon\Mvc\Model\Validator\Uniqueness;
class Tags extends \Phalcon\Mvc\Model {
public $id;
public $project_id;
public $name;
public function initialize() {
$this->setSource('table_tags');
}
public function validation()
{
$this->validate(new Uniqueness([
'field' => ['project_id', 'name'],
'message' => 'The tag already exists in selected project'
]));
return ($this->validationHasFailed() != true);
}
}
Lets say I have the following data:
$data = array(
'id' => 1,
'project_id' => 1,
'name' => 'Some tag',
);
It works fine when creating a new record with Tags::save(), but then Tags::update() is failing the validation. There might be something I’m missing here or the Uniqueness validation is not excluding current $id from the check.
Tested on: Phalcon 1.3.0 and 1.2.4 PHP 5.4.18 and 5.5.5 Windows 7
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- Merge pull request #1600 from WooDzu/1.3.0-issue-1527 [BUG] Test case for issue #1527 — committed to phalcon/cphalcon by deleted user 11 years ago
The bug seems to be back with version 2.1.0.RC1. I rolled back to a previous version 2.0.8 released on Sep 26 2015 16:25:52 which works fine.