Open atrandafir opened 1 month ago
It seems to me like your model is not extending the right subclass.
Can you show us the model code ?
Sure @machour this is the model's code:
<?php
namespace common\models\mongo;
use Yii;
/**
* @property \MongoDB\BSON\ObjectID|string $_id
* @property string $ent_name
* @property string $ent_fsid
* @property string $lab_code
* @property string $ent_summary
* @property string $ent_url
* @property string $palette
* @property string $picture_url
*/
class Lab extends \yii\mongodb\ActiveRecord {
public static function collectionName() {
return 'fst-labs';
}
public function attributes() {
return [
'_id',
'ent_name',
'ent_fsid',
'lab_code',
'ent_summary',
'ent_url',
'palette',
'picture_url',
];
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
['ent_name', 'safe'],
['ent_fsid', 'safe'],
['lab_code', 'safe'],
['ent_summary', 'safe'],
['ent_url', 'safe'],
// ['palette', 'safe'],
['picture_url', 'safe'],
];
}
public function attributeLabels() {
return [
];
}
}
The model was created manually copying code from a previous project but if I try to generate with Gii I get a similar result:
<?php
namespace common\models;
use Yii;
/**
* This is the model class for collection "fst-labs".
*
* @property \MongoDB\BSON\ObjectID|string $_id
*/
class FstLabs extends \yii\mongodb\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function collectionName()
{
return 'fst-labs';
}
/**
* {@inheritdoc}
*/
public function attributes()
{
return [
'_id',
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'_id' => 'ID',
];
}
}
Oh, it seems that mongodb requires an extra configuration to be used with Gii, could you check if you have this in place in your configuration? https://www.yiiframework.com/extension/yiisoft/yii2-mongodb/doc/guide/2.0/en/topics-gii
Yes I do and if I'm not wrong that has nothing to do with CRUD generation but Model generation.
What steps will reproduce the problem?
What's expected?
What do you get instead?
Call to undefined method common\models\mongo\Lab::getTableSchema()
Additional info
This is the code causing the error and it is part of https://github.com/yiisoft/yii2-gii package actually, but I'm not sure if the error comes from Gii or this extension needs some tweaking so it doesn't show up.
What I did see is that in the past it worked, but Gii was updated and it stopped working. Previously the code was:
So as a workaround if you swap one line with the other it works. But again this is Gii code.
Also second lighter error
create
action:Calling unknown method: common\models\mongo\Lab::loadDefaultValues()