Mongodb Activerecord

Guys,

In my Mongodb ActiveRecord I have





public function attributes()

    {

        return ['_id', 'name', 'desc', '];

    }


public function rules()

    {

        return [

            [['name'], 'required'],

        ];

    }




When I send update form and save model, desc attribute changes not saved.

but if I apply required rule on desc,it will be save.

any idea?

add type to your attribute(desc) in rules like this : [[‘desc’],‘string’]

The reason is that in Yii2, attributes are treated UNSAFE by default for massive assignment. Yii by default sets the attribute to safe, if you have at least one validation model rule defined.

The solution is for you to define the attributes you want safe by using scenarios. OR you need to do implicitly set your attributes as safe:




public function rules()

{

    return [

        [['name', 'attrib1', 'attrib2'], 'safe'], // set all attribs you want as safe

    ];

}