-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
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
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.