Question

I am trying to pull data from a table. To do this I have used

mage::getModel('module/model')->getData

this has returned an empty array, but i can't work out why as the table i am calling holds data.

There is a discrepancy between this model

class Ps_Prefs_Model_Prefsformelements
extends Mage_Core_Model_Abstract
{
protected function _construct()
{
    $this->_init('ps_prefs/prefsformelements');
}

}

class Ps_Prefs_Model_Resource_Prefsformelements
extends Mage_Core_Model_Resource_Db_Abstract
{
protected function _construct()
{
    $this->_init('ps_prefs/prefsformelements', 'idform_elements');
}
}

class Ps_Prefs_Model_Resource_Prefsformelements_Collection
extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct()
{
    $this->_init('ps_prefs/prefsformelements');
}
}

and other models in my module. That descripency lies in the namespace_module/... part of the call. as you can see this model uses namespace_module/... while my other models work fine with just module/... I have tried run the above code using just module/... but I get the error can't retrieve entity config but if I try to run the other using this namespace_module/... I start throwing errors why?

I had considered my config but if that is the case why am I not getting errors when I use namespace_module/... and why wont it work when I make it conform to the other models?

===

EDIT

===

<config>
...
  <global>        
    <models>
        <prefs>
            <class>Ps_Prefs_Model</class>
            <resourceModel>prefs_resource</resourceModel>
        </prefs>

        <prefs_resource>
            <class>Ps_Prefs_Model_Resource</class>
            <entities>
                <prefs>
                    <table>prefcentre</table>
                </prefs>
                <prefsemail>
                    <table>prefcentre_options</table>
                </prefsemail>
                <prefsform>
                    <table>pref_form_elements</table>
                </prefsform>
            </entities>
        </prefs_resource>
    </models>
  ...
</global>
...
</config>
Was it helpful?

Solution

I think the problem is that you do not have a definition for the table prefs/prefsformelements. If you look at how the init for the resource works it takes the following:

/**
 * Standard resource model initialization
 *
 * @param string $mainTable
 * @param string $idFieldName
 * @return Mage_Core_Model_Resource_Abstract
 */
protected function _init($mainTable, $idFieldName)
{
    $this->_setMainTable($mainTable, $idFieldName);
}

So looking at this and your config.xml you are missing the table that matches prefsformelements but your have others that you might have mixed up the names for.

<prefsformelements>
    <table>pref_form_elements</table>
</prefsformelements>

OTHER TIPS

Use Mage::getModel instead of mage::getModel.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top