I am trying to use loadMultiple to load 2 models at one time, but it seams that doesn’t work?
Can someone test it?
Documentation here
I am trying to use loadMultiple to load 2 models at one time, but it seams that doesn’t work?
Can someone test it?
Documentation here
How exactly it doesn’t work?
I have the same problem with loadMultiple().
For my case, I have 2 models: $vendor and $location, when creating new record:
$vendor->load(Yii::$app->request->post()) return true
$location->load(Yii::$app->request->post()) return true
Model::loadMultiple([$vendor,$location], Yii::$app->request->post()) return false
I’ve looked at the source in model.php. If I change line 781 to 784 from:
} elseif (isset($data[$scope][$i])) {
$model->setAttributes($data[$scope][b][$i][/b]);
$success = true;
}
to
} elseif (isset($data[$scope])) {
$model->setAttributes($data[$scope]);
$success = true;
}
then it will work.
Yes I already found this problem, and apply the same solution, but since it is a core error on yii2 I decide to use 2 times the load method, for now.
Bit of a late reply, but, unless I am missing something the $models paramater says in the documentation, that they should be of the same class.
@param array $models the models to be populated. Note that all models should have the same class.