Yii2: enanchment : Model should auto cast datatype

Created on 10 Jun 2016  路  6Comments  路  Source: yiisoft/yii2

Actually loading data that are not casted to the appropriate data type (in particular numbers) cause the attribute to be marked as dirty even if the value is not changed, this cause:

  • dirty attribute checking method to fail
  • run update query when is not necessary

Actually to avoid this you need to manually setup filters to cast the value to the appropriate data type.

Since Model knows attribute data type the value should be casted to the appropriate data type automatically.

This would save a lot of time avoiding setting up filters that are always needed for optimal coding and errors giving false positive during dirty checking.

Samdark is proposing to plan it as an enhancement for 2.1
http://www.yiiframework.com/forum/index.php?showtopic=70660&view=getnewpost

enhancement

Most helpful comment

@yiisoft/core-developers what do you think about doing it by default?

All 6 comments

@yiisoft/core-developers what do you think about doing it by default?

Is this related too to PHP PDO returning everything as strings? I know that there, one could get the necessary behavior by disabling emulate prepares.

Yes and yes. Still, disabling emulated prepares isn't always desired.

Can be solved by #12067

Yes. That's the best way to solve it so far.

Resolved by #12067

Was this page helpful?
0 / 5 - 0 ratings