OmgDef / yii2-multilingual-behavior

Yii2 port of the yii-multilingual-behavior.
146 stars 60 forks source link

languageField attribute is not working #24

Closed alexweb-zz closed 9 years ago

alexweb-zz commented 9 years ago

Looks like languageField attribute is not working:

    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
            [
                'class' => MultilingualBehavior::className(),
                'languages' => [
                    Language::LANGUAGE_ENGLISH,
                    Language::LANGUAGE_RUSSIAN,
                ],
                'languageField' => 'language_id',
                'dynamicLangClass' => false,
                'abridge'=>false,
                'langClassName' => CategoryI18n::className(),
                'defaultLanguage' =>  Language::LANGUAGE_ENGLISH,
                'langForeignKey' => 'category_id',
                'attributes' => [
                    'name', 'description', 'logo',
                ]
            ],
        ];
    }

Category::find()->localized(Language::LANGUAGE_ENGLISH)->where(['id'=>1])->one();

I got the following error: "Column not found: 1054 Unknown column 'language' in 'where clause'"

OmgDef commented 9 years ago

@alexweb You should override $languageField property in your query class https://github.com/OmgDef/yii2-multilingual-behavior/blob/master/src/MultilingualTrait.php#L16

OmgDef commented 9 years ago

@alexweb something like this

class MyQuery extends MultilingualQuery
{
    public $languageField = 'language_id';
}
OmgDef commented 9 years ago

@alexweb also if you set abridge property to false you should call localized scope with second parameter Post::find()->localized('en-US', false)->where(['id' => 2])->one()

alexweb-zz commented 9 years ago

Ok, thanks