CakeDC / users

Users Plugin for CakePHP
https://www.cakedc.com
Other
521 stars 296 forks source link

RegistryAlias is not the right one #985

Closed Cyrille37 closed 2 years ago

Cyrille37 commented 2 years ago

Hi

After login the user entity is of the right type App\Model\Entity\UserOverride which I configured in Config.Users.table but its property _registryAlias is 'Users' where it should be 'UserOverrides'.

Here is a var_export( $user ) extract :

2022-02-23 06:49:16 debug: App\Model\Entity\UserOverride::__set_state(array(
   '_accessible' => 
  array (
    '*' => true,
    'id' => false,
    'is_superuser' => false,
    'role' => false,
    'group_id' => true,
  ),
...
   '_dirty' => 
  array (
    'last_login' => true,
  ),
   '_new' => false,
   '_errors' => 
  array (
  ),
   '_invalid' => 
  array (
  ),
   '_registryAlias' => 'Users',
))
steinkel commented 2 years ago

How are you extending/configuring the UserOverride Entity & the UserOverridesTable please?

Cyrille37 commented 2 years ago

Yes :-)

namespace App\Model\Table;
use CakeDC\Users\Model\Table\UsersTable;
/**
 * Application specific Users Table with non plugin conform field(s)
 */
class UserOverridesTable extends UsersTable
{
    /**
     * CakeDc table name.
     */
    const TABLENAME = 'users';
    public function initialize(array $config): void
    {
        parent::initialize($config);
        $this->setTable( self::TABLENAME );
        $this->addBehavior('Timestamp');
    }
}

namespace App\Model\Entity;
use CakeDC\Users\Model\Entity\User;
/**
 * @inheritdoc
 * @property integer $group_id
 */
class UserOverride extends User
{
    public function __construct(array $properties = [], array $options = [])
    {
        parent::__construct($properties, $options);
        $this->_accessible['group_id'] =  true;
    }
}
steinkel commented 2 years ago

Using $this->setRegistryAlias() or not extending directly the UsersTable, but appending the behaviors you need should do the trick for you...

Cyrille37 commented 2 years ago

Thanks @steinkel setRegistryAlias() do the job :-)