Hey guys, I have some relational attributes (e.g post_id) at my model, all integers. I did some rules declaring it integers. When i find a model, all integers attributes are casting correctly (all integer attributes has correct type in php), less my relational attributes that are casted like string. What did i lost?
I need get correctly all dirty attributes to implement a simple revision data system.
Model Rules
public function rules()
{
return [
...
[['quantity', 'id_publisher', 'id_licensor', 'id_category', 'enabled'], 'integer'],
[['quantity'], 'filter', 'filter' => function ($value) { return $value == '' ? null : intval($value);}], // Avoid mark as dirty attribute (integer)
[['id_publisher'], 'filter', 'skipOnError' => false, 'filter' => function ($value) { return $value == '' ? null : intval($value);}], // Avoid mark as dirty attribute (integer)
[['id_licensor'], 'filter', 'skipOnError' => false, 'filter' => function ($value) { return $value == '' ? null : intval($value);}], // Avoid mark as dirty attribute (integer)
[['id_category'], 'filter', 'skipOnError' => false, 'filter' => function ($value) { return $value == '' ? null : intval($value);}], // Avoid mark as dirty attribute (integer)
[['id_publisher'], 'exist', 'skipOnError' => true, 'targetClass' => Publisher::className(), 'targetAttribute' => ['id_publisher' => 'id']],
[['id_licensor'], 'exist', 'skipOnError' => true, 'targetClass' => Publisher::className(), 'targetAttribute' => ['id_licensor' => 'id']],
[['id_category'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['id_category' => 'id']],
...
];
}
Schema data
$this->createTable('magazines', [
'id' => $this->primaryKey(11)->unsigned()->notNull(),
'id_publisher' => $this->integer(11)->unsigned(),
'id_licensor' => $this->integer(11)->unsigned(),
'id_category' => $this->integer(11)->unsigned(),
...
'quantity' => $this->integer(5),
'enabled' => $this->smallInteger(1)->unsigned()->notNull()->defaultValue(1),
...
], $tableOptions);
Expected values:
array(14) { ... ["id_publisher"]=> int(1) ["id_licensor"]=> int(1) ["id_category"]=> int(1)["quantity"]=> int(1) ["enabled"]=> int(1) ... }
Get instead values:
array(14) { [... ["id_publisher"]=> string(1) "1" ["id_licensor"]=> string(1) "1" ["id_category"]=> string(1) "1" ["quantity"]=> int(1) ["enabled"]=> int(1) ... }