Magento quick getResourceModel question
Asked Answered
A

3

6

What class (if any) is called with this line of code?

Mage::getResourceModel('sales/order_invoice_collection')

Essentially I"m trying to figure out what database table is accessed with this resource model and how I can tweak that. Thanks!

Arsenic answered 2/8, 2011 at 17:6 Comment(0)
E
14

The class you are looking for is this:

Mage_Sales_Model_Mysql4_Order_Invoice_Collection

located in app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php.

If you take a look at the configuration for the sales module app/code/core/Mage/Sales/etc/config.xml, you can see the table name in the definition of the resource models:

<config>
    <global>
        <models>
            <sales_mysql4>
                <entities>
                    ...
                    <invoice><table>sales_flat_invoice</table></invoice>
                    ...
                </entities>
            </sales_mysql4>
        </models>
    </global>
</config>

To learn more about how Magento interacts with the database, you should read about models, resource models, and collections:

http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics

Elspet answered 2/8, 2011 at 17:39 Comment(2)
Ah beat me to it, and with better formatting. Though, shouldn't the relevant portion of the config file be the <resourceModel> tag?Ilarrold
Well, you are more correct, heh. The <resourceModel> tag points to the <sales_mysql4> tag, which contains the <class> tag that ultimately points to the directory in question.Ilarrold
U
5

Try this to get the class resulting from a statement:

$obj = Mage::getResourceModel('sales/order_invoice_collection');
print get_class($obj);
Uncleanly answered 2/8, 2011 at 17:34 Comment(0)
I
4

In this instance it is loading

code/Core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php 

which is class name:

Mage_Sales_Model_Mysql4_Order_Invoice_Collection

This can be determined by looking at the config.xml:

code/Core/Mage/Sales/etc/config.xml. 

In it under the models tag is the sales tag, which you know from 'sales' before the slash in the string. There it defines the resource model as sales_mysql4. So, if you call:

Mage::getResourceModel('module/everything_else')

the file loaded will be:

Module/Model/{contents of resourceModel tag}/Everything/Else.php

Hope that helps.

Ilarrold answered 2/8, 2011 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.