XF 2.1 Entity column and relations issue

grantus

Active member
This is part of my Entity:

Code:
$structure->columns = [
            'battle_id' => ['type' => self::UINT, 'autoIncrement' => true],
            'battle_date' => ['type' => self::UINT, 'default' => 0],
            'category' => ['type' => self::STR, 'default' => '', 'maxLength' => 15],
            'battle' => ['type' => self::UINT, 'default' => 0],
            'user_id' => ['type' => self::UINT, 'default' => 0],
            'username' => ['type' => self::STR, 'default' => '', 'maxLength' => 50],
            'points' => ['type' => self::UINT, 'default' => 0, 'maxLength' => 5],
            'winner' => ['type' => self::STR, 'default' => 'no', 'maxLength' => 3],
        ];
        $structure->relations = [
            'User' => [
                'entity'     => 'XF:User',
                'type'       => self::TO_ONE,
                'conditions' => 'user_id',
                'primary'    => true
            ],
        ];

I want to add this to my relations:

Code:
$structure->relations = [
            'Cat' => [
                'entity'     => 'Battles\ILL:BiuArchives',
                'type'       => self::TO_ONE,
                'conditions' => 'battle'
            ],
        ];

But the issue I'm facing is this: 'entity' => 'Battles\ILL:BiuArchives' will depend on what the 'category' is in the $structure->columns.

For example how can I figure out if the column value is something like 'BiuArchives' or 'BthisArchives'?
 
The ORM doesn't really support dynamic relationship entities like that. You would have to define them as separate relations. You could tie them together with a getter if you want to be able to access them from the same virtual property though.
 
Top Bottom