XF 2.2 question about altering a table

dsick

Member
I'm running into an issue when I alter a table and add a new column, the new column doesn't exist and I get other errors like unknown getter, and some says the field is unknown, I know how to do the custom entities but is it a different approach for an existing table that you're altering..

This is my entity class

PHP:
<?php

namespace rblapps\rbL1\Entity;

use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;

class PollResponse extends \XF\Entity\PollResponse
{
    public static function getStructure(Structure $structure)
    {

        $structure = parent::getStructure($structure);

        $structure->table = 'xf_poll_response';
        $structure->columns = [
            'user_id' => ['type' => self::UINT],
        ];

        return $structure;
    }
 
}
 
you know there seems to be an issue with the way I was doing the columns.

this is where the error came from, it seems to be having a problem with how I defined them like an array.
Code:
 $structure->columns = [
            'user_id' => ['type' => self::UINT],
        ];
but if I do it like this, everything works as expected.

Code:
        $structure->columns['feedback_score'] = ['type' => Entity::UINT, 'default' => 0];

above is how they do it on the lets build an addon page, but they have the columns as arrays if you look in the XF folder.
 
Good catch, since you're extending the structure you don't want to overwrite the column property completely.
 
Good catch, since you're extending the structure you don't want to overwrite the column property completely.
yea i was having an issue where if its a user table, it was basically overwriting the entire column like you said and I get errors saying a lot of stuff is missing, seems to be working now. I can even call the added user column on the xf:visitor which is nice.
 
Back
Top Bottom