I’ve met a problem about linked db with MSSQL. I have two servers which are hosting different db. On my local server, I set the remote one thanks to linked db functionality so that I can request db of both servers.
Below a model from remote db.
class FCONTACTT extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'AIG-FIC.'.yii::$app->params['parametres']['dbSAGE'].'.dbo.F_CONTACTT';
}
/**
* @return \yii\db\Connection the database connection used by this AR class.
*/
public static function getDb()
{
return Yii::$app->get('dbSAGE');
}
}
Below error I get.
Below a statement which works and returns expected results.
But the next requests are bad due to the fake name of table:
I guess the problem is coming from getTableSchema() of the model ActiveRecord.
/**
* Declares the name of the database table associated with this AR class.
* By default this method returns the class name as the table name by calling [[Inflector::camel2id()]]
* with prefix [[Connection::tablePrefix]]. For example if [[Connection::tablePrefix]] is 'tbl_',
* 'Customer' becomes 'tbl_customer', and 'OrderItem' becomes 'tbl_order_item'. You may override this method
* if the table is not named after this convention.
* @return string the table name
*/
public static function tableName()
{
return '{{%' . Inflector::camel2id(StringHelper::basename(get_called_class()), '_') . '}}';
}
/**
* Returns the schema information of the DB table associated with this AR class.
* @return TableSchema the schema information of the DB table associated with this AR class.
* @throws InvalidConfigException if the table for the AR class does not exist.
*/
public static function getTableSchema()
{
$tableSchema = static::getDb()
->getSchema()
->getTableSchema(static::tableName());
if ($tableSchema === null) {
throw new InvalidConfigException('The table does not exist: ' . static::tableName());
}
return $tableSchema;
}
How could I fix this problem ?
Best regards
Edit:
(Currently trying to override the tableName() function)