Class humhub\components\behaviors\PolymorphicRelation

Inheritancehumhub\components\behaviors\PolymorphicRelation » yii\base\Behavior
Available since version0.5

PolymorphicRelations behavior provides simple support for polymorphic relations in ActiveRecords.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$classAttribute string The class name attribute humhub\components\behaviors\PolymorphicRelation
$mustBeInstanceOf array The related object needs to be a "instanceof" at least one of these given classnames humhub\components\behaviors\PolymorphicRelation
$pkAttribute string The primary key attribute humhub\components\behaviors\PolymorphicRelation
$strict boolean If set to true an exception is thrown if object_model and object_id is set but does not exist humhub\components\behaviors\PolymorphicRelation

Public Methods

Hide inherited methods

MethodDescriptionDefined By
getPolymorphicRelation() Returns the Underlying Object humhub\components\behaviors\PolymorphicRelation
loadActiveRecord() Loads an active record based on classname and primary key. humhub\components\behaviors\PolymorphicRelation
resetPolymorphicRelation() Resets the already loaded $_cached instance of related object humhub\components\behaviors\PolymorphicRelation
setPolymorphicRelation() Sets the related object humhub\components\behaviors\PolymorphicRelation

Property Details

$classAttribute public property

The class name attribute

public string $classAttribute 'object_model'
$mustBeInstanceOf public property

The related object needs to be a "instanceof" at least one of these given classnames

$pkAttribute public property

The primary key attribute

public string $pkAttribute 'object_id'
$strict public property

If set to true an exception is thrown if object_model and object_id is set but does not exist

public boolean $strict false

Method Details

getPolymorphicRelation() public method

Returns the Underlying Object

public mixed getPolymorphicRelation ( )
throws \yii\db\IntegrityException
loadActiveRecord() public static method

Loads an active record based on classname and primary key.

public static null|\yii\db\ActiveRecord loadActiveRecord ( $className, $primaryKey )
$className
$primaryKey
resetPolymorphicRelation() public method

Resets the already loaded $_cached instance of related object

public void resetPolymorphicRelation ( )
setPolymorphicRelation() public method

Sets the related object

public void setPolymorphicRelation ( $object )
$object mixed