How to get magento table name

I have this global configuration:

<global>
    <models>
    <subscriber>
        <class>Giftlab_Subscriber_Model</class>
        <resourceModel>subscriber_resource</resourceModel>
    </subscriber>
    <subscriber_resource>
        <class>Giftlab_Subscriber_Model_Resource</class>
        <entities>
            <records>
                <table>subscriber_records</table>
            </records>
        </entities>
    </subscriber_resource>
    </models>
    <resources>
        <giftlab_subscriber_write>
            <connection>
                <use>core_write</use>
            </connection>
        </giftlab_subscriber_write>
        <giftlab_subscriber_read>
            <connection>
                <use>core_read</use>
            </connection>
        </giftlab_subscriber_read>
        <giftlab_subscriber_setup>
            <setup>
                <module>Giftlab_Subscriber</module>
                <class>Giftlab_Subscriber_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </giftlab_subscriber_setup>
    </resources>
</global>

in my mysql4-install-0.1.0.php file, I need to get the table name. How should I do it? I know this is something like this:

$this->getTable('subscriber_resource/records')

But this causes only an exception Can't retrieve entity config: subscriber_resource/records. What do I need to do to get the table name?

+5
source share
3 answers

I found out the answer myself, although thanks to @ Yaroslav for managing my study guide Alan Storm, how it helped.

Answer: I need this:

$this->getTable('subscriber/records');

"" - ( ), "" - . , magento thinga/thingb, , - , <thinga><resourceModel>{resourcemodel}, <{resourcemodel}><entities><thingb><table>, .

, , . , - - .

+13

Magento Collections. . :

$mysubscriber_recordsCollection = Mage::getModel('records/subscriber_records')->getCollection()

Alan Storm, Magento.

EDIT

, . $installer->getTable('records/subscriber_records'), .

<?php
    echo 'Running This Upgrade: '.get_class($this)."\n <br /> \n";
    $installer = $this;
    $installer->startSetup();
    $installer->run("
        CREATE TABLE `{$installer->getTable('records/subscriber_records')}` (
            `subscriber_records_id` int NOT NULL AUTO_INCREMENT,
            PRIMARY KEY (`subscriber_records_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    ");
    $installer->endSetup();

Alan Storm

+2

If you want to get the table name of a resource that doesn’t have a resource model (for example catalog/category_product), and you are not in the script setup, you can do it as follows:

$table = Mage::getSingleton('core/resource')->getTableName('catalog/category_product');

This is useful for all N: M relationships, where you usually don't need a model class.

+2
source

All Articles