XF 2.1 UINT can't be 0

Hoffi

Well-known member
I encountered a strange issue this weekend.

Via Listener I added a new row in the Post table.

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

With some updater all went fine, until i reduced the counter until it was 0.

I wans't able to set this field to 0.

XenForo delivered the error:

Please enter a number that is at least 0

After changing the field to INT, all works fine.
 

Chris D

XenForo developer
Staff member
We have many UINT fields in XF which are perfectly functional and do not give any errors when set to 0.

I can only assume at this point that there was something else wrong with your code so will move to dev discussions for now.
 

Hoffi

Well-known member
Here is the code. This class is added via Classextension to the post Entity.

PHP:
    public function updateMyCounter(int $amount)
    {
        if (!$amount)
            $amount = 1;

        $this->my_counter = max(0, $this->my_counter += $amount);
        $this->save();
    }

If I misundertood something, please let me know.

But only after I changed the structure in the Listener.php for the structure, this works.
PHP:
 $structure->columns['my_counter'] = ['type' => Entity::INT, 'default' => 0 ];
 
Top