Getter on href returns null


#1

I have a data object “packaging” with a href to another data object, “product”. This returns null, “$package->getProduct();” If I var_dump($package), I can see:

class Pimcore\Model\DataObject\ProductPackingMethod#996 (38) {
public $o_classId =>
string(2) “51”
public $o_className =>
string(20) “ProductPackingMethod”
public $product =>
** class Pimcore\Model\DataObject\Product#1049 (62) {**
public $o_classId =>
string(2) “26”
public $o_className =>
string(7) “Product”
public $ItemNumber =>
string(6) “100091”
public $ItemName =>
string(32) “Stay-Dry Milk-Catcher Bibs (3pk)”
public $tblSizeRange =>

But, the getter doesn’t grab it and $package->product is a private variable.


#2

OK, it was because the “product” was unpublished. I see how to change this when querying for relations but how do you do it when calling the getter getProduct()?


#3

Got it:

DataObject\AbstractObject::setHideUnpublished(false);