Error creating or updating model
ettolo opened this issue · 1 comments
ettolo commented
Hi OmgDef, thank you for this usefull extension!
I've used in another project (same version) and everything is fine.
In the new project i can't get it work, i get this error:
Getting unknown property: common\models\Calibers::description, notes
description and notes are fields in the calibersLang table.
The Calibers model is the following:
namespace common\models;
use Yii;
use omgdef\multilingual\MultilingualBehavior;
use omgdef\multilingual\MultilingualQuery;
/**
* This is the model class for table "calibers".
*
* @property integer $id
* @property string $inch_diam
* @property string $mm_diam
* @property integer $sort
*
* @property CalibersLang[] $calibersLangs
*/
class Calibers extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'calibers';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['inch_diam', 'mm_diam'], 'required'],
[['sort'], 'integer'],
[['inch_diam', 'mm_diam'], 'string', 'max' => 255],
[['description', 'notes'], 'required'],
[['description, notes'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('cartucios', 'ID'),
'inch_diam' => Yii::t('cartucios', 'Diameter in inches'),
'mm_diam' => Yii::t('cartucios', 'Diameter in mm'),
'sort' => Yii::t('cartucios', 'Sort'),
'description' => Yii::t('cartucios', 'Description [ITA]'),
'description_en' => Yii::t('cartucios', 'Description [EN]'),
'notes' => Yii::t('cartucios', 'Notes [ITA]'),
'notes_en' => Yii::t('cartucios', 'Notes [EN]'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCalibersLangs()
{
return $this->hasMany(CalibersLang::className(), ['calibers_id' => 'id']);
}
public function behaviors()
{
return [
'ml' => [
'class' => MultilingualBehavior::className(),
'languages' => [
'it' => 'Italiano',
'en' => 'English',
],
//'languageField' => 'language',
//'localizedPrefix' => '',
//'requireTranslations' => 'false',
//'dynamicLangClass' => 'true',
//'langClassName' => CalibersLang::className(), // or namespace/for/a/class/PostLang
'defaultLanguage' => 'it',
'langForeignKey' => 'calibers_id',
'tableName' => "calibersLang",
'attributes' => [
'description', 'notes',
]
],
];
}
public static function find()
{
return new MultilingualQuery(get_called_class());
}
}
If i remove description and notes from validation rules then i get no error but fields are not saved in the table.
Like in the working project i made, i've not created the calibersLang class
Any idea?
Thanks in advance!
Best regards,
Nicola