-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: You must specify either the alias or the table option for the constructor #6
Comments
What version are you running? Please try to update to the newest version. This plugin uses Cakes TableRegistry get to initiate tables earlier this method was using deprecated version (TableRegistry::get) but has now been updated to newest way (TableRegistry::getTableLocator()->get) I did some fast testing on this. I created a custom <?php
declare(strict_types=1);
namespace App\Model\Table;
use Cake\ORM\Table as BaseTable;
class Table extends BaseTable
{
public function MyCustomFunction(): string
{
return 'im custom';
}
} And this is my UsersTable that extends the custom table <?php
declare(strict_types=1);
namespace App\Model\Table;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use App\Model\Table\Table;
use Cake\Validation\Validator;
/**
* Users Model
*
* @property \App\Model\Table\LoginTokensTable&\Cake\ORM\Association\HasMany $LoginTokens
*
* @mixin \Cake\ORM\Behavior\TimestampBehavior
*/
class UsersTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('users');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->hasMany('LoginTokens', [
'foreignKey' => 'user_id',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
return $rules;
}
} This setup worked for me without issues. |
I just tested on latest
class Table extends \Cake\ORM\Table
{
public function initialize(array $config): void
{
$this->addBehavior('Search.Search');
}
}
abstract class Table extends \Cake\ORM\Table
{
//something
}
class Table extends \Cake\ORM\Table
{
public function initialize(array $config): void
{
debug($this->getTable());
}
} Contents of Table.php does not really matters. What matters is that you create instance of this class in first place (and you do it without passing required parameters to table constructor) |
When creating instance of
|
Thank you for the clearer example. I have reproduced this problem and the changes in the pull request were correct. |
All of my app tables are extending custom
\App\Model\Table\Table
Your plugin incorrectly tries to create instance of this
\App\Model\Table\Table
class:And ends up with following error page:
Your plugin has same problem with dereuromark/cakephp-tools plugin because it contains
\Tools\Model\Table\Table
classThe text was updated successfully, but these errors were encountered: