php - Yii2 elasticsearch setAttributes() not working -
i using yii 2.1 , yii2-elasticsearch 2.0.3 elasticsearch 1.5.0 server try , index member model more powerful search. have common\indexes\member
model extends yii\elasticsearch\activerecord
, set attributes want index.
namespace common\indexes; use yii\elasticsearch\activerecord; class member extends activerecord { /** * @return array list of attributes record */ public function attributes() { // path mapping '_id' setup field 'id' return ['id', 'given_name', 'family_name', 'email']; } }
i having trouble setting attributes want in common\indexes\member
model.
i creating new instance of object , trying set attribute values via activerecord setattributes() method doesn't seem set values.
$index = new common\indexes\member(); $index->setattributes(['given_name' => 'test', 'family_name' => 'user', 'email' => 'test.member@test.com']); $index->save();
this seems create empty record. if manually set attributes 1 one seems work , record correct attributes created in elasticsearch database.
$index = new common\indexes\member(); $index->given_name = 'test'; $index->family_name = 'user'; $index->email = 'test.member@test.com'; $index->save();
am using setattributes()
method incorrectly elasticsearch activerecord's? need set elasticsearch model differently?
by default setattributes
sets attributes have @ least single validation rule defined or - minimum - defined being "safe" (either via safeattributes()
or via safe-validator).
you can force assign changing call
$index->setattributes([ 'given_name' => 'test', 'family_name' => 'user', 'email' => 'test.member@test.com' ], false);
this tells it okay assign non-safe attributes. prefer make sure the validation configured correctly
Comments
Post a Comment