Возник такой, казалось бы легкий вопрос, но никак не могу врубиться, почему так происходит.
Product.php
Код: Выделить всё
public function getProductAttachments()
{
return $this->hasMany(ProductAttachment::className(), ['product_id' => 'id']);
}
Код: Выделить всё
public function getUrl()
{
if ($this->base_url && $this->path) {
return $this->base_url . '/' . $this->path;
} else {
return false;
}
}
Код: Выделить всё
$items = \common\models\Product::find()->all();
foreach ($items as $item) {
$images = $item->getProductAttachments();
foreach ($images as $image) {
$url = $image->getUrl();
}
}
Код: Выделить всё
Call to a member function getUrl() on null
Код: Выделить всё
Array
(
)
common\models\ProductAttachment
1
common\models\Product Object
(
и так далее.
Где я косячу?