Skip to content

Commit bd99031

Browse files
author
Eugene Tupikov
committed
Add hasAttribute checking for ActiveRecord models
1 parent 00e4afc commit bd99031

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/MultipleInput.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,25 @@ public function getElementName($name, $index, $withPrefix = true)
314314
private function getInputNamePrefix($name)
315315
{
316316
if ($this->hasModel()) {
317-
if (empty($this->columns) || (count($this->columns) == 1 && $this->model->hasProperty($name))) {
317+
if (empty($this->columns) || (count($this->columns) == 1 && $this->hasModelAttribute($name))) {
318318
return $this->model->formName();
319319
}
320320
return Html::getInputName($this->model, $this->attribute);
321321
}
322322
return $this->name;
323323
}
324324

325+
private function hasModelAttribute($name)
326+
{
327+
if ($this->model->hasProperty($name)) {
328+
return true;
329+
} elseif ($this->model instanceof ActiveRecord && $this->model->hasAttribute($name)) {
330+
return true;
331+
} else {
332+
return false;
333+
}
334+
}
335+
325336
/**
326337
* Returns element id.
327338
*

0 commit comments

Comments
 (0)