php - Phalcon ORM - integer field id is string after save
问题描述
I'm using Phalcon for my current project and i'm seeing some strange behaviour with the type casting.
I have this model
class Customer extends Model {
protected $id;
protected $name;
}
In my service, i save a new Customer
model like this:
$customer = new Customer();
$customer->name = 'test';
$customer->save();
var_dump($customer->id);
The problem i'm facing is that the id
is a string, instead of an integer
. In db
the fiend of course is an auto increment int, primary key.
Also, I have already added those lines in my db connection
\Pdo::ATTR_PERSISTENT => false,
\Pdo::ATTR_EMULATE_PREPARES => false,
\Pdo::ATTR_STRINGIFY_FETCHES => false,
which only solves the problem when you fetch from database and not when you save.
I don't want to use a getter for id, since I have implemented another functionality with magic setters/getters.
Any solution on this issue?
解决方案
The correct issue for this problem is https://github.com/phalcon/cphalcon/issues/13002 and has been resolved now. Just use
Model::setup([ 'castLastInsertIdToInt' => TRUE ]);
in your bootstrapping to activate workaround globally
推荐阅读
- android - Exoplayer 搜索栏预览
- ruby-on-rails - 当我尝试启动服务器时出现错误“您已尝试在 Spring 已加载时调用它”
- javascript - 单击按钮时,我无法从列表中搜索项目
- r - 使用传单在 rshiny 中创建缩略图
- c - GCC 不合格?
- scrapy - Scrapy 错误:TypeError:__init__() 得到了一个意外的关键字参数“cb_kwargs”
- c# - SqlGeography.STPolyFromText - 引发错误 24201:纬度值必须在 -90 到 90 度之间
- javascript - 从数组中获取对象并推送到新数组
- html - 使按钮不可见,仅在悬停在 div 上或输入内有文本时显示
- python - 在新的 Google 标签上粘贴数据