Answer the question
In order to leave comments, you need to log in
Magento get table without prefix
Hello, is there a table?
<entities>
<user>
<table>oem_user</table>
</user>
</entities>
protected function _construct()
{
$this->_init('mass/user', 'id');
}
Answer the question
In order to leave comments, you need to log in
It often happens that he asked himself, answered himself.
I overridden the getTableName method
and did as written here
stackoverflow.com/questions/2417134/how-to-override-table-name-andprefix-in-magento-model
class Meta_Mass_Model_Resource extends Mage_Core_Model_Resource
{
public function getTableName($modelEntity)
{
$tableSuffix = null;
if (is_array($modelEntity)) {
list($modelEntity, $tableSuffix) = $modelEntity;
}
$parts = explode('/', $modelEntity);
if (isset($parts[1])) {
list($model, $entity) = $parts;
$entityConfig = false;
if (!empty(Mage::getConfig()->getNode()->global->models->{$model}->resourceModel)) {
$resourceModel = (string)Mage::getConfig()->getNode()->global->models->{$model}->resourceModel;
$entityConfig = $this->getEntity($resourceModel, $entity);
}
if ($entityConfig && !empty($entityConfig->table)) {
$tableName = (string)$entityConfig->table;
} else {
Mage::throwException(Mage::helper('core')->__('Can\'t retrieve entity config: %s', $modelEntity));
}
} else {
$tableName = $modelEntity;
}
Mage::dispatchEvent('resource_get_tablename', array(
'resource' => $this,
'model_entity' => $modelEntity,
'table_name' => $tableName,
'table_suffix' => $tableSuffix
));
$mappedTableName = $this->getMappedTableName($tableName);
if ($mappedTableName) {
$tableName = $mappedTableName;
} else {
if($entityConfig->ignore_prefix) {
$tablePrefix = '';
} else {
$tablePrefix = (string)Mage::getConfig()->getTablePrefix();
}
$tableName = $tablePrefix . $tableName;
}
if (!is_null($tableSuffix)) {
$tableName .= '_' . $tableSuffix;
}
return $this->getConnection(self::DEFAULT_READ_RESOURCE)->getTableName($tableName);
}
}
<models>
<core>
<rewrite>
<resource>Meta_Mass_Model_Resource</resource>
</rewrite>
</core>
</models>
The fact is that it (the prefix) should be added, it's like a rule of the engine. If you use manually created tables without a prefix, this does not mean that the magenta should know about it, you gave it the name of the entity, it gets it and adds a prefix, everything is reasonable. And I think it's wrong to override
this method.
Try this, but I'm not sure about this method.
<entities>
<user>
<table>oem_user</table>
<prefix></prefix>
</user>
</entities>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question