Fetch default value from schema

33 views Asked by At

In my database I have some mandatory columns that have a default value:

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')
);

While I can often just ignore them, there're circumstances where I need to have such default value in my controller so I can:

  • Display it to user (so he has the chance to approve or replace it)
  • User it in further calculations before saving

Is there a way to fetch that value automatically, so I don't have to duplicate the schema information somewhere else?

0

There are 0 answers