-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The integer id field is being populated as a string after save #13002
Comments
Yes, good catch. We need to respect column map types and cast appropriately right here as MySQL lastInsertId() always returns string https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model.zep#L2432-L2434 Always returns string |
Ahh I thought lastinsertid may have been the root cause but never had time to check! I'm still new to Phalcon so wouldn't know how to check the mapped type! Thanks for the work on narrowing it down. |
Any updates on this? |
Anything on this ? |
@zeecher I will check on this this coming week after I attend some other pressing matters. Thank you for reporting this |
this is really annoying |
What is complete version of MySQL? And show output of
|
for now solved it by overriding model's toArray
|
The proper solution is to just cast to (int) here: https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model.zep#L2486-L2489 PHP returns string from MySQL's internal call which returns bigint. There's no reason why we shouldn't just cast to int in the code ... |
This gets really annoying when using |
I've been talking about this with the core team. The issues at play are:
If either if the above are true. I believe ... that we should properly handle for the following PDO extensions:
Thus, with respect to MySQL/MariaDB ... lastInsertId() should always be sufficient to fit inside a PHP 64bit integer. However, we can't do this for 100% of the cases (e.g. users that don't fit into the top two bullets listed above). So we could introduce a new global value I guess the other thought is we could pull the column map for the field and if it's INT and Thus, the reason for the explicit and separate global which removes any crazy logic in terms of attempting to autodetect how to handle this case. Thus, potential solution would be a 3 line change with effectively zero performance impact. For example:
Thoughts? Ping @phalcon/core-team |
Resolved in #14068 |
Expected and Actual Behavior
When I save a model, the id field is automatically populated with the id value, however, instead of it being an integer value, it's populated as a string value. When outputting json this is an issue. In the database, the id field is an
integer auto_increment primary key
, and in the annotations, the `@Column' type is an integer. (I'm using the annotation strategy)e.g. instead of seeing:
"id":5,
I get"id":"5"
Details
php --ri phalcon
) 3.2.1php -v
) 7The text was updated successfully, but these errors were encountered: