View more context

 

markcl

it seems my old code that does this for SS3 does not work

Admonish

In silverstripe 4 how would you tell if a hasOne relationship is set or filled? I have has one relationship called "Discount" on my Product (DataObject) class. I want to do something like "If this product has a discount record associated with it do..."

Admonish

Ahh thank you, I was looking for the

  1. !$record->Relationship()->exists()
which I have used before in the past

Admonish

But I guess

  1. $record->Discount() !== null
would work to

Admonish

I always thought there was something special about exist() behind the scenes. I never thought of just testing for a null value\