nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
309 stars 59 forks source link

Entity - getter* on NULL #85

Closed f3l1x closed 9 years ago

f3l1x commented 9 years ago
/**
 * @property Image|NULL    $image    {1:1d ImagesRepository primary}
 */
class Book extends Entity
{

    /**
     * @return string
     */
    protected function getterImage()
    {
        die('OK');
    }
}

In referenced column does not work getter*. In my case if image is NULL.

I guess cause of that - https://github.com/nextras/orm/blob/master/src/Entity/AbstractEntity.php#L420-L422

hrach commented 9 years ago

Ok, I was thinking and this is probably wont fix. Getters are not supported for IPropertyContainers. If you need getter eg. for placeholder, use new virtual property.

/**
 * @property Image|NULL    $image    {1:1d ImagesRepository primary}
 * @property-read Image     $imageAlways {virtual}
 */
class Book extends Entity
{
    protected function getterImageAlaways()
    {
          return $this->image ?: new Image('placeholder');
    }
}

We should probably add doc for this and also throw exception when you defined getter|setter for IPropertyContianer.

f3l1x commented 9 years ago

Yes. It's oukey. I have already do that.

Thanks for adding to doc.