Answer the question
In order to leave comments, you need to log in
Phalcon phql handling duplicate key
Hello.
Such a question, could not find the answer in the documentation and on the community forum.
There is a fairly simple table (MySQL). It has a title field with a UNIQUE index. Accordingly, something like this is done in the controller:
$Pages = new Pages();
$Pages->title = !empty ($streamPage['title']) ? $streamPage['title'] : 'Untitled';
$Pages->active = 1;
if ($Pages->save() == false){
foreach ($Pages->getMessages() as $errorMessage){
error_log ($errorMessage);
}
continue;
}
Answer the question
In order to leave comments, you need to log in
Offhand solution. In the model, in beforeSave, do a search for an existing title. Accordingly, if found - update, otherwise - create.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question