I've tried doing the following, but it does not work.
$products = DataObject::get('Product'); // Product has a has_one relationship to Image
$images= DataObject::get('Image');
foreach ($products as $product) {
foreach ($images as $image) {
if ($product->ImageID == $image->ID) {
$product->setComponent('Image', $image);
break;
}
}
}
// even though an image has been assigned, it still queries the database.
$products->First()->Image();
Has anyone else had this issue?