The current table Structure is:
+---------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| title | varchar(25) | NO | UNI | NULL | |
| content | varchar(500) | NO | | NULL | |
+---------------+------------------+------+-----+---------+----------------+
Model:
<?php
namespace Com\Models;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;
class Articles extends Model
{
/**
*
* @var integer
*/
public $id;
/**
*
* @var string
*/
public $title;
/**
*
* @var string
*/
public $content;
/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'articles';
}
/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return Articles[]
*/
public static function find($parameters = null)
{
return parent::find($parameters);
}
/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return Articles
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}
/**
* Validate if article titles are unique
*/
public function validation()
{
$this->validate(new Uniqueness([
"field" => "title",
"message" => "Please select a different title."
]));
return $this->validationHasFailed() != true;
}
}
We are receiving the error: id is required