public save ( boolean $runValidation = true, array $attributeNames = null ) : boolean | ||
$runValidation | boolean | whether to perform validation (calling [[\yii\base\Model::validate()|validate()]]) before saving the record. Defaults to `true`. If the validation fails, the record will not be saved to the database and this method will return `false`. |
$attributeNames | array | list of attribute names that need to be saved. Defaults to `null`, meaning all attributes that are loaded from DB will be saved. |
리턴 | boolean | whether the saving succeeded (i.e. no validation errors occurred). |
public function save($runValidation = true, $attributeNames = null);
/** * @param array $link * @param ActiveRecordInterface $foreignModel * @param ActiveRecordInterface $primaryModel * @throws InvalidCallException */ private function bindModels($link, $foreignModel, $primaryModel) { foreach ($link as $fk => $pk) { $value = $primaryModel->{$pk}; if ($value === null) { throw new InvalidCallException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.'); } if (is_array($foreignModel->{$fk})) { // relation via array valued attribute $foreignModel->{$fk} = array_merge($foreignModel->{$fk}, [$value]); } else { $foreignModel->{$fk} = $value; } } $foreignModel->save(false); }