Returns a value indicating whether the model has an attribute with the specified name.
public hasAttribute ( string $name ) : boolean | ||
$name | string | the name of the attribute |
return | boolean | whether the model has an attribute with the specified name. |
/** * @inheritdoc */ public function __set($name, $value) { if ($this->_relation->hasAttribute($name) || $this->_relation->canGetProperty($name)) { $this->_relation->{$name} = $value; } else { parent::__set($name, $value); } }
/** * Fills up default attributes for the variation model. * @param BaseActiveRecord $variationModel model instance. * @throws InvalidConfigException on invalid configuration. */ private function fillUpVariationModelDefaults($variationModel) { if ($this->variationModelDefaultAttributes === null) { $variationsRelation = $this->owner->getRelation($this->variationsRelation); if (isset($variationsRelation->where)) { foreach ((array) $variationsRelation->where as $attribute => $value) { if ($variationModel->hasAttribute($attribute)) { $variationModel->{$attribute} = $value; } } } return; } if (is_callable($this->variationModelDefaultAttributes, true)) { call_user_func($this->variationModelDefaultAttributes, $variationModel); return; } if (!is_array($this->variationModelDefaultAttributes)) { throw new InvalidConfigException('"' . get_class($this) . '::variationModelDefaultAttributes" must be a valid callable or an array.'); } foreach ($this->variationModelDefaultAttributes as $attribute => $value) { $variationModel->{$attribute} = $value; } }