6

I'm getting the following error after moving a Magento 1.9.1 project from my local Vagrant box to a remote server:

Fatal error: Call to a member function beginTransaction() on boolean in /var/www/html/app/code/core/Mage/Core/Model/Abstract.php on line 313

This errors points to this section of code:

$this->_getResource()->beginTransaction();

Where $this->_getResource is returning false. This seems to be caused by either a Model autoloading issue, or models not getting initialized correctly but I cannot find the cause.

The app has no errors locally, and I don't see any major differences between my server environment and local environment. Here are the config files and model files that are relevant to the problem

config.xml

<models>
    <company_xmpieformbuilder>
        <class>Company_XMPieFormBuilder_Model</class>
        <resourceModel>xmpieformbuilder_resource</resourceModel>
    </company_xmpieformbuilder>
    <xmpieformbuilder_resource>
        <class>Company_XMPieFormBuilder_Model_Resource</class>
        <entities>
            <configuration>
                <table>company_xmpieformbuilder_configuration</table>
            </configuration>
            <fieldset>
                <table>company_xmpieformbuilder_fieldset</table>
            </fieldset>
            <field>
                <table>company_xmpieformbuilder_field</table>
            </field>
            <fieldtype>
                <table>company_xmpieformbuilder_field_type</table>
            </fieldtype>
            <fieldinputcontrol>
                <table>company_xmpieformbuilder_field_input_control</table>
            </fieldinputcontrol>
            <fieldattributes>
                <table>company_xmpieformbuilder_field_attributes</table>
            </fieldattributes>
            <fieldpossiblevalues>
                <table>company_xmpieformbuilder_field_possible_values</table>
            </fieldpossiblevalues>
            <fieldrule>
                <table>company_xmpieformbuilder_field_rule</table>
            </fieldrule>
            <fieldruletype>
                <table>company_xmpieformbuilder_field_rule_type</table>
            </fieldruletype>
            <fieldvaluesource>
                <table>company_xmpieformbuilder_field_value_source</table>
            </fieldvaluesource>
        </entities>
    </xmpieformbuilder_resource>
    <core>
        <rewrite>
            <abstract_model>Company_Core_Model_Abstract</abstract_model>
        </rewrite>
    </core>
    <catalog>
        <rewrite>
            <product>Company_Catalog_Model_Product</product>            
        </rewrite>
    </catalog>
</models>

Example model, all the models are empty similar to this.

class Company_XMPieFormBuilder_Model_Configuration extends Company_Core_Model_Abstract {

    protected function _construct()
    {
        $this->_init('company_xmpieformbuilder/configuration');
    }

}

Base model.

class Company_Core_Model_Abstract extends Mage_Core_Model_Abstract {
}
5

The problem comes from the declaration of the resources and the name used in the models.

So instead of :

<xmpieformbuilder>
    <class>Company_XMPieFormBuilder_Model</class>
    <resourceModel>xmpieformbuilder_resource</resourceModel>
</xmpieformbuilder>

And then in your models you need to call:

$this->_init('xmpieformbuilder/configuration');

That comes from the fact that you declares your entities using the xmpieformbuilder_resource tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.