Skip to content

Commit 2c4ca72

Browse files
author
Eugene Tupikov
committed
proper handling AR relations
1 parent ae0f7f9 commit 2c4ca72

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/BaseColumn.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ protected function prepareValue()
198198
} else {
199199
$value = null;
200200
if ($data instanceof ActiveRecordInterface ) {
201-
$value = $data->getAttribute($this->name);
201+
$relation = $data->getRelation($this->name, false);
202+
if ($relation !== null) {
203+
$value = $relation;
204+
} else {
205+
$value = $data->getAttribute($this->name);
206+
}
202207
} elseif ($data instanceof Model) {
203208
$value = $data->{$this->name};
204209
} elseif (is_array($data)) {
@@ -207,7 +212,7 @@ protected function prepareValue()
207212
$value = $data;
208213
}
209214

210-
if ($this->isEmpty($value) && $this->defaultValue !== null) {
215+
if ($this->defaultValue !== null && $this->isEmpty($value)) {
211216
$value = $this->defaultValue;
212217
}
213218
}

0 commit comments

Comments
 (0)