i define the table name in model like:
public function tableName()
{
return '{{node}}';
}
if my tablePrefix set to "yii_" in db config,
how can i get "yii_node" through the model~?
i define the table name in model like:
public function tableName()
{
return '{{node}}';
}
if my tablePrefix set to "yii_" in db config,
how can i get "yii_node" through the model~?
Try AR::model()->tableSchema->rawName.
I haven’t used tablePrefix before so just guessing.
it will be return ‘{{node}}
’
just wrap by quote~
qiang?
Have just had to do this myself from within an active record.
preg_replace('/{{(.*?)}}/',$this->getDbConnection()->tablePrefix.'\1',$this->tableName())
This is the way its done in CDbCommand. Don’t know why theres no dedicated method for it!
Wouldn’t this do just fine ?
//Your model :
public function getOriginalTableName()
{
return Yii::app()->db->tablePrefix.str_replace(array('{{','}}'),'',$this->tableName());
}
Probably, just going with what Yii already uses. Maybe theres some performance considerations?
str_* functions are faster than preg_* functions.
Model::model()->tableSchema->name;
$productTableName = ProductModel::getTableSchema()->fullName;