CMTV
Well-known member
Hi!
I want for
But somethimes there is no row in
How to create a default row every time the relation returns
I tired this but it is not working:
But I get an error:
I want for
Trophy
entity to have default relation with TrophyData
entity.
PHP:
$structure->relations = array_merge($structure->relations, [
'UP' => [
'entity' => 'UserProgression:TrophyData',
'type' => self::TO_ONE,
'conditions' => 'trophy_id',
'primary' => true
]
]);
$structure->defaultWith = array_merge($structure->defaultWith, ['UP']);
But somethimes there is no row in
xf_UP_trophy_data
table for needed TrophyData
entity and relation returns null
.How to create a default row every time the relation returns
null
?I tired this but it is not working:
PHP:
$structure->getters = array_merge($structure->getters, [
'UP' => ['getter' => 'getUP']
]);
public function getUP()
{
if(!$this->UP)
{
$trophyData = $this->em->create('UserProgression:TrophyData');
$trophyData->setTrusted('trophy_id', $this->trophy_id);
$trophyData->save();
}
return $this->UP;
}
But I get an error: