i am using onCondition in my model relation
public function getCompanyModuleCustFieldsGroupsNameTs()
{
return $this->hasOne(CompanyModuleCustFieldsGroupsNameT::className(), ['translated_item_id' => 'id'])
->onCondition('[company_module_cust_fields_groups_name_t].[language_id] = :lang', [':lang' => Yii::$app->language]);
}
and i am getting an error on ActiveDataProvider
SQLSTATE[07002]: [Microsoft][ODBC Driver 11 for SQL Server]COUNT field incorrect or syntax error
The SQL being executed was: SELECT COUNT(*) FROM [company_module_custom_fields] LEFT JOIN [company_module_cust_fields_groups] ON [company_module_custom_fields].[group_id] = [company_module_cust_fields_groups].[id] LEFT JOIN [company_module_cust_fields_groups_name_t] ON ([company_module_cust_fields_groups].[id] = [company_module_cust_fields_groups_name_t].[translated_item_id]) AND ([company_module_cust_fields_groups_name_t].[language_id] = 'fr') LEFT JOIN [company_module_custom_fields_name_t] ON ([company_module_custom_fields].[id] = [company_module_custom_fields_name_t].[translated_item_id]) AND ([company_module_custom_fields_name_t].[language_id] = 'fr') WHERE ([company_module_custom_fields].[company_id]='56') AND ([company_module_custom_fields].[module_id]='8')
the query passed to ActiveDataProvider is
$query = CompanyModuleCustomFields::find()
->joinWith(['group','group.companyModuleCustFieldsGroupsNameTs', 'companyModuleCustomFieldsNameTs'])
->Select('company_module_custom_fields.name')
->addSelect('company_module_custom_fields_name_t.translation');
The count query is working in SQL server but not in YII
what i am doing wrong?
I did some tests and the error shows up only when i use more then one relation with onCondition
Thanks