Following the example given here I have written:
if($this->request->isPost() == true) {
$new_record= new NewRecord();
$new_record->name = $this->request->getPost("Name");
$new_record->label = ucwords($new_record->name);
if ($new_record->create() == false) {
echo "Umh, We can't store a New Record right now: \n";
foreach ($new_record->getMessages() as $message) {
echo $message, "\n";
}
} else {
$this->flashSession->success("News Record created");
return $this->response->redirect('admin/news/newrecord');
}
}
In the database I have a unique constraint on the 'name' field in table 'NewRecord'.
The problem I am having is that when I create a duplicate record coming up against the unique constraint the application is exiting and ouputting:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Interview' for key 'news_group_label_UNIQUE'
This happens before getting to the first echo statement in the if.
Is this happening because I have not mapped the constraint in the model? ( I haven't)
In phalcon do I have to explicitly map the database constraints in the model?
Is the style to make all constraints in the model and leave the database alone?