从架构中获取默认值

时间:2016-12-29 09:38:21

标签: cakephp cakephp-2.5

在我的数据库中,我有一些具有默认值的必填列:

public $quotation_lines = array(
    'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'primary'),
    'quotation_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'),
    'description' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 100, 'collate' => 'utf8_spanish_ci', 'charset' => 'utf8'),
    'price' => array('type' => 'decimal', 'null' => false, 'default' => null, 'length' => '14,2', 'unsigned' => false),
    'quantity' => array('type' => 'decimal', 'null' => false, 'default' => '1.00', 'length' => '12,2', 'unsigned' => false),
    //                                                        ^^^^^^^^^^^^^^^^^^^
    'total' => array('type' => 'decimal', 'null' => false, 'default' => null, 'length' => '14,2', 'unsigned' => false,),
    'indexes' => array(
        'PRIMARY' => array('column' => 'id', 'unique' => 1),
        'FK_quotation_lines_quotation_id' => array('column' => 'quotation_id', 'unique' => 0),
    ),
    'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_spanish_ci', 'engine' => 'InnoDB')
);

虽然我经常可以忽略它们,但在我需要在我的控制器中拥有这样的默认值的情况下,我可以:

  • 向用户显示(因此他有机会批准或替换它)
  • 在保存之前将其用于进一步的计算

有没有办法自动获取该值,因此我不必在其他地方复制架构信息?

0 个答案:

没有答案