Commit abb2a0db by Qiang Xue

minor improvement of label generation.

parent eeff0ea6
...@@ -1124,7 +1124,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -1124,7 +1124,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
/** @var $viaClass ActiveRecord */ /** @var $viaClass ActiveRecord */
/** @var $record ActiveRecord */ /** @var $record ActiveRecord */
$record = new $viaClass(); $record = new $viaClass();
foreach($columns as $column => $value) { foreach ($columns as $column => $value) {
$record->$column = $value; $record->$column = $value;
} }
$record->insert(false); $record->insert(false);
...@@ -1300,19 +1300,22 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -1300,19 +1300,22 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
$labels = $this->attributeLabels(); $labels = $this->attributeLabels();
if (isset($labels[$attribute])) { if (isset($labels[$attribute])) {
return ($labels[$attribute]); return ($labels[$attribute]);
} elseif(strpos($attribute, '.')) { } elseif (strpos($attribute, '.')) {
$attributeParts = explode('.', $attribute); $attributeParts = explode('.', $attribute);
$neededAttribute = array_pop($attributeParts); $neededAttribute = array_pop($attributeParts);
$relatedModel = $this; $relatedModel = $this;
foreach ($attributeParts as $relationName) { foreach ($attributeParts as $relationName) {
try { if (isset($this->_related[$relationName]) && $this->_related[$relationName] instanceof self) {
$relation = $relatedModel->getRelation($relationName); $relatedModel = $this->_related[$relationName];
} catch (InvalidParamException $e) { } else {
return $this->generateAttributeLabel($attribute); try {
$relation = $relatedModel->getRelation($relationName);
} catch (InvalidParamException $e) {
return $this->generateAttributeLabel($attribute);
}
$relatedModel = new $relation->modelClass;
} }
$relatedModel = new $relation->modelClass;
} }
$labels = $relatedModel->attributeLabels(); $labels = $relatedModel->attributeLabels();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment