XF 2.1 Accessing custom DB tables

jazz_aaf

Well-known member
Hi,


I have created a new custom table in the database. The relation between the new table and the AttachmentData table was added like the following:

Code:
        $structure->relations =
        [
            'AttachmentData' => [
                'entity' => 'XF:AttachmentData',
                'type' => self::TO_ONE,
                'conditions' => 'data_id',
                'primary' => true
            ]
        ];

The same was added to the entity "AttachmentData":

Code:
    public static function getStructure(Structure $structure)
    {
        $structure = parent::getStructure($structure);
            
            
        $structure->relations = array_merge(
            $structure->relations,
            [
                'AttachmentCheck' => [
                    'entity' => 'Jazzaaf\AttachmentCheck:AttachmentCheck',
                    'type' => self::TO_ONE,
                    'conditions' => 'data_id',
                    'primary' => true
                ],
            ]
        );

In the "attachment_macros" template, the new table values are only available for the attachments of the first post of the thread, and "NULL" for attachments of the replies in the same thread.

Any idea why this is happening?

Thank you.
 
Where a specific code event exists, a listener should be created to utilise it rather than a full class extension.
Try this:
Code:
 public static function getStructure(Structure $structure)
    {
        $structure = parent::getStructure($structure);

        $structure->relations += [
                'AttachmentCheck' => [
                    'entity' => 'Jazzaaf\AttachmentCheck:AttachmentCheck',
                    'type' => self::TO_ONE,
                    'conditions' => 'data_id',
                    'primary' => true
                ]
        ];
       
        return $structure;
        }
 
Last edited:
Where a specific code event exists, a listener should be created to utilise it rather than a full class extension.
Are you sure? I see different approaches here looking at 3rd party addons. But I know mixing class extensions and event listeners for structure extensions can cause trouble..
 
Where a specific code event exists, a listener should be created to utilise it rather than a full class extension.
Try this:
Code:
 public static function getStructure(Structure $structure)
    {
        $structure = parent::getStructure($structure);

        $structure->relations += [
                'AttachmentCheck' => [
                    'entity' => 'Jazzaaf\AttachmentCheck:AttachmentCheck',
                    'type' => self::TO_ONE,
                    'conditions' => 'data_id',
                    'primary' => true
                ]
        ];
     
        return $structure;
        }

Thank you for the suggestion. Unfortunately, that did not change the situation. "AttachmentCheck" table values are still shown for the first post, but not the replies.

I would believe it is a bug and the thread should be moved to the bugs forum.

EDIT: Never mind. Found the error. Thank you all.

Regards.
 
Last edited:
Back
Top Bottom