Hello to everyone, this is my first post here, I read the forum rules so I hope getting this right.
In a project I have a multiple DB configuration following the steps of the wiki: Multiple Databases and Multiple Domains
Actually it works great (and have more than 4 DB), even I can write this in the view a column of a CGridView:
Where rel3 is in another DB.
My problem is when I want to order some data when creating a CActiveDataProvider:
$valDataProvider =new CActiveDataProvider('Class1',array( 'criteria'=>array('with' => array('relClass1',relClass1.relClass2' ), 'together'=>true, 'order' => 'relClass1.relClass2.columnName DESC', ) ));
This gets me the error :
CDbCommand falló al ejecutar la sentencia SQL: SQLSTATE[HY000] [-1] Invalid object name 'dbo.table1'.
Translated it says:
CDbCommand failed to execute the SQL Query: SQL:SQLSTATE[HY000] [-1] Invalid object name 'dbo.table1'
Now for what I have discovered, can’t find the DB table (because is searching in DB1 instead of DB2).
I searched in Yii code but actually I just suppose that happens two things:
I did something wrong
Yii is generating a bad sql query
I hope I have make my problem clear and I would really appreciate a little bit of help, thank you everyone
Yii version : 1.1.10
DB Manager : Microsoft SQL Server 2008
Browsing Yii code, it is a difference between eager loading and lazy loading (the next statements perhaps are incomplete or incorrect but well I’m trying to undestand what is happening), when is a eager loading, in CActiveFinder, when is contructing the tree, it goes and ask the schema to the CDbCommandBuilder of each model and then CDbSchema returns the schema and name of the table and the connection is assumed of the model where was call. So then when the tree is passed to CDbCommand and is constructing the query, in the method
From (see line 695 from de CDBCommand source code [can’t put link becasuse is my first post]) it just joining each part of the string but not its DB, so then when try to make the query; actually I already see the log and it gave me this:
CDbCommand::fetchColumn() failed: SQLSTATE[HY000] [-1] Invalid object name 'dbo.anotherDBTbName'.. The SQL statement executed was: SELECT COUNT(DISTINCT [t].[col1]) FROM [dbo].[tb1] [t] LEFT OUTER JOIN [dbo].[tb2] [codigoOperadoresRel] ON ([t].[tb1]=[codigoOperadoresRel].[col1]) LEFT OUTER JOIN [dbo].[anotherDBTbName] [innoCanAltClientes] ON ([codigoOperadoresRel].[col1]=[innoCanAltClientes].[col1])
So I’m guessing, is this a bug?