We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Error : Phalcon\Mvc\Model::_doLowInsert(): Property should be string

I create table in mysql :

CREATE TABLE api_failed_logins
(
  user_id INT UNSIGNED NOT NULL,
  logs LONGTEXT,
  ip VARCHAR(15) NOT NULL,
  PRIMARY KEY (user_id, ip)
);

then meta data in Model

public function metaData()
    {
        return array(

            //Every column in the mapped table
            MetaData::MODELS_ATTRIBUTES => array(
                 'user_id', 'ip','logs'
            ),

            //Every column part of the primary key
            MetaData::MODELS_PRIMARY_KEY => array(
                'user_id','ip'
            ),

            //Every column that isn't part of the primary key
            MetaData::MODELS_NON_PRIMARY_KEY => array(
                 'logs'
            ),

            //Every column that doesn't allows null values
            MetaData::MODELS_NOT_NULL => array(
                'user_id','ip'
            ),

            //Every column and their data types
            MetaData::MODELS_DATA_TYPES => array(
                'user_id' => Column::TYPE_INTEGER,
                'logs' => Column::TYPE_TEXT,
                'ip' => Column::TYPE_VARCHAR,
            ),

            //The columns that have numeric data types
            MetaData::MODELS_DATA_TYPES_NUMERIC => array(
                'user_id' => true
            ),

            //The identity column, use boolean false if the model doesn't have
            //an identity column
            MetaData::MODELS_IDENTITY_COLUMN => array('user_id','ip'),

            //How every column must be bound/casted
            MetaData::MODELS_DATA_TYPES_BIND => array(
                'user_id' => Column::BIND_PARAM_INT,
                'logs' => Column::BIND_PARAM_STR,
                'ip' => Column::BIND_PARAM_STR,
            ),

            //Fields that must be ignored from INSERT SQL statements
            MetaData::MODELS_AUTOMATIC_DEFAULT_INSERT => array(
                //'created' => 100
            ),

            //Fields that must be ignored from UPDATE SQL statements
            MetaData::MODELS_AUTOMATIC_DEFAULT_UPDATE => array(
                // 'modified' => true
            )

        );
    }

when it inserts it's succesful and my database has one record but display error : Phalcon\Mvc\Model::_doLowInsert(): Property should be string . When update it's always succesful . I don't know why when insert it show error. Please explan for me.

Thanks Vu

You're missing one index:

MetaData::MODELS_DEFAULT_VALUES => array(),
edited Jun '15

Thanks for your reply.

It is display error again.

Step 1 : Follow your answers .

I modify metaData function with six parttern and apply once :

MetaData::MODELS_DEFAULT_VALUES => array(),

MetaData::MODELS_DEFAULT_VALUES => array('user_id','ip'),

MetaData::MODELS_DEFAULT_VALUES => array(NULL,NULL),

MetaData::MODELS_DEFAULT_VALUES => array(NULL),

MetaData::MODELS_DEFAULT_VALUES => array('user_id'=>NULL,'ip'=>NULL),

MetaData::MODELS_DEFAULT_VALUES => array('user_id'=>0,'ip'=>NULL),

when Model->save , insert ok , record inserted in databse .continue show error.

when Model->update it is ok

Continue

I disable metaData function . It is ok for insert and update.

but when i cache metadata.

   $di->set('modelsMetadata', function()  {
         return new \Phalcon\Mvc\Model\MetaData\Apc(array(
         "lifetime" => 86400,
         "prefix"   => "modelsMetadata"
         )
   );
   });

Model->save , insert ok , record inserted in databse .continue show error.

Model->update it is ok.

Step 2 : Use phql

$phql    = "INSERT INTO VApi\Models\FailedLogins (user_id, ip, logs) VALUES (1,8 ,2)";
$result = $app->modelsManager->executeQuery($phql) ; 

insert ok , record inserted in databse .continue show error.

Step 3 : insert direct wiith sql INSERT INTO api_failed_logins (user_id, ip, logs) VALUES (1,8 ,2) ; it is ok , check mysql log is ok.

Why insert , data has inserted in database. But it show error .

**Error : 
    (
        [type] => 2
        [message] => Phalcon\Mvc\Model::_doLowInsert(): Property should be string
        [file] => D:\xxx\xxx\htdocs\phalcon\pha-api\app\v\failed_logins\log.php
        [line] => 22
    )
 **

You don't need to cache meta-data

edited Jun '15

I modify metaData function with six parttern , apply once :

MetaData::MODELSDEFAULTVALUES => array(), 

MetaData::MODELSDEFAULTVALUES => array('user_id','ip'), 

MetaData::MODELS_DEFAULT_VALUES => array(NULL,NULL), 

MetaData::MODELS_DEFAULT_VALUES => array(NULL),

MetaData::MODELS_DEFAULT_VALUES => array('user_id'=>NULL,'ip'=>NULL),

MetaData::MODELSDEFAULTVALUES => array('user_id'=>0,'ip'=>NULL),

when Model->save , insert ok , record inserted in databse .continue show error.



60

MetaData::MODELS_IDENTITY_COLUMN => array('user_id','ip')

MetaData::MODELS_IDENTITY_COLUMN => "user_id";

or

MetaData::MODELS_IDENTITY_COLUMN => "ip";

or

MetaData::MODELS_IDENTITY_COLUMN => false

/**
 * Sends a pre-build INSERT SQL statement to the relational database system
 *
 * @param \Phalcon\Mvc\Model\MetaDataInterface $metaData 
 * @param \Phalcon\Db\AdapterInterface $connection 
 * @param string|array $table 
 * @param ★★boolean|string★★ $identityField 
 * @return boolean 
 */
protected function _doLowInsert(\Phalcon\Mvc\Model\MetaDataInterface $metaData, \Phalcon\Db\AdapterInterface $connection, $table, $identityField) {}