Model properties of DECIMAL data type MySQL
Posted 10 April 2012 - 11:43 AM
I've used Gii to create a model from MySQL table which contains some fields of the DECIMAL (10,2) data type (for storing currency amounts).
Gii recognized these fields as a string fields. As I understand the alteration of rules() will be necessary (a change to 'numerical', 'integerOnly'=>false, etc.). I found some posts regarding that.
Yet I'd like to ask you if there are any other consequences that I should be careful about when using a DECIMAL type.
Posted 10 April 2012 - 02:30 PM
When converting currencies, you may use up to 4 (or more) decimal places.
Thank you for your suggestions. It's actually going to be play money yet I'll consider adding more decimal places anyway. As you mentioned it may be important for some conversions later on.
Still I'm curious if there any specific issues with DECIMAL type in Yii framework or the only issue is that Gii doesn't recognize the type and everything else work smoothly?
Posted 10 April 2012 - 05:24 PM
I think the only thing I specified is: the max length, to right-align the text fields in my _form, and add the currency and the VAT inc./excl. mention:
<?php echo $form->textField($model,'amount',array('maxlength'=>13,'style'=>'text-align:right')); ?><span class="CUR"></span>
(I set the span content via jQuery depending on other fields)
Posted 11 April 2012 - 02:34 AM
To be sure I've tried Gii once more on a different table. It creates:
// @property string $amount
array('amount', 'length', 'max'=>10),
As I mentioned it's ok for me to change the rules. I just wanted to make sure there are no other consequences that wouldn't be apparent at a first sight. I'm sorry if I'm bringing up an irrelevant matter. I've just started with Yii so I haven't fully got my feet under the table yet.