问题
Situation
using cake 3.2.4
Was using the method addDefaults()
to set the type decimal
. Was wondering the following:
- what other types are there that I can set?
- is it possible to set precision and scale when setting decimal in the method
addDefaults()
Code that prompted that thinking
$this->paginate['fields'] = [
'id', 'title',
'start' => 'start_date',
'end' => 'end_date',
'revenue',
'costs' => 'total_costs', 'collections'
];
$paginationQuery = $event->subject()->query;
$paginationQuery
->selectTypeMap()
->addDefaults([
'start' => 'datetime',
'end' => 'datetime',
'costs' => 'decimal'
]);
What I tried
I tried researching the docs
http://api.cakephp.org/3.2/class-Cake.Database.TypeMap.html#_addDefaults
and also the class itself http://api.cakephp.org/3.2/source-class-Cake.Database.TypeMap.html#17-149
To no avail.
回答1:
what other types are there that I can set?
The available types can be found in the cookbook
Cookbook > Database Access & ORM > Database Basics > Data Types
and in the source
- https://github.com/cakephp/cakephp/tree/3.2.5/src/Database/Type
- https://github.com/cakephp/cakephp/blob/3.2.5/src/Database/Type.php#L27-L64
is it possible to set precision and scale when setting decimal in the method addDefaults()
As mentioned in the comments, PHP swallows trailing zero decimals, that's just how it works, if you want to "keep" them, then you should format the numbers when outputting them.
Cookbook > Number > Formatting Numbers
来源:https://stackoverflow.com/questions/35973135/what-are-the-acceptable-types-used-in-the-class-typemap-in-cake-3-x