Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

id is required

Hey guys, when a try to give a Lists->create() in a controller my method is return that the field id is required but a set he this way:

    id int unsigned not null auto_increment primary key,
    name varchar,
if($n_list->create() === false){
                    echo "Error: xxx";
                    $messages = $n_list->getMessages();

                    foreach ($messages as $message) {
                        echo $message, "\n";

It can be a problem of cache?

I'am using PHP 7.1 and Maria DB.

Perhaps you did not delete models meta data cache?

edited Dec '17

I try debug with:

$lists = new Lists();
    $metadata = $lists->getModelsMetaData();
$attributes = $metadata->getAttributes($lists);
    $dataTypes = $metadata->getDataTypes($lists);


Array ( [0] => id [1] => name [2] => url [3] => description [4] => id_subject [5] => list_type [6] => source [7] => allow_votes [8] => id_media [9] => id_user [10] => id_category ) 

Array ( [id] => 0 [name] => 2 [url] => 2 [description] => 2 [id_subject] => 0 [list_type] => 0 [source] => 2 [allow_votes] => 0 [id_media] => 0 [id_user] => 0 [id_category] => 0 )

and I try use reset() in meta data cache but nothings happens

edited Dec '17

Can you show us how you set your models meta cache in your services?

Should look something like this:

$di->setShared('modelsMetadata', function() use ($config) {
    return new \Phalcon\Mvc\Model\MetaData\Files([
        'lifetime' => 86400,
        'metaDataDir' => $config->site->path->cache . 'models-metadata/'

edited Dec '17

I was not setting this, how was it working before? I was seeing this now and trying use Apc, and what this $config variable should be? is just for the path of the metaDataDir? Thanks.

--Edit again: I set the modelsMetadata as you sugest and continue returning the message that id is required. I use create in anothers models and works fine but in this specifically don't work but I can't find any difference in the code.

edited Dec '17

I think that I found the error in my code, I was setting a foreign key of a relation 1:1 this way:

$tl_list->Media = $media; // I was trying object media and aparently this expect the id
$tl_list->id_media = $media->id; // and works 

GOod job solving it yourself! Sorry for not replying yesterday, fell asleep on the couch :)