Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Model create does not return id #37

@SanhDoan

Description

@SanhDoan

Hi everyone, I have started used this framework for few weeks and I got an issue that when I use Model::create(), it doesn't auto assign id to my model
For example:

$user = new User();
$user->name = "My name";
$user->create();

echo $user->id; // Result always is "0"

I tried it with raw Phalcon, and got correct id (auto increment) after create

I searched it on google and found this solution, set persistent => true in config/database.php

'mysql' => [
            'host'     => env('DB_HOST', 'localhost'),
            'port'     => env('DB_PORT', 3306),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'dbname'   => env('DB_DATABASE', 'slayer'),
            'persistent' => true,
            'charset'  => env('DB_CHARSET', 'utf8'),
            'class'    => Phalcon\Db\Adapter\Pdo\Mysql::class,
        ],

But I think this solution is not the correct approach. Could you please help to show me what I should do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions