diff --git a/phalcon/Mvc/Model.zep b/phalcon/Mvc/Model.zep index d035db8ec94..3d48cd08d67 100644 --- a/phalcon/Mvc/Model.zep +++ b/phalcon/Mvc/Model.zep @@ -2761,7 +2761,7 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface exceptionOnFailedSave, phqlLiterals, virtualForeignKeys, lateStateBinding, castOnHydrate, ignoreUnknownColumns, updateSnapshotOnSave, disableAssignSetters, - caseInsensitiveColumnMap, prefetchRecords; + caseInsensitiveColumnMap, prefetchRecords, lastInsertId; /** * Enables/Disables globally the internal events @@ -2845,6 +2845,10 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface if fetch prefetchRecords, options["prefetchRecords"] { globals_set("orm.resultset_prefetch_records", prefetchRecords); } + + if fetch lastInsertId, options["castLastInsertIdToInt"] { + globals_set("orm.cast_last_insert_id_to_int", lastInsertId); + } } /** @@ -3619,6 +3623,13 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface */ let lastInsertedId = connection->lastInsertId(sequenceName); + /** + * If we want auto casting + */ + if unlikely globals_get("orm.cast_last_insert_id_to_int") + let lastInsertedId = intval(lastInsertId, 10); + } + let this->{attributeField} = lastInsertedId; let snapshot[attributeField] = lastInsertedId;