I am currently struggling through my first magento project and it seems to be leaving me with asking more questions than it has answered.
My current hurdle is adding default data to a child table.
I have two tables user and preferences I have created these by adding them directly to the database (for simplicity sake)
My plan is that when a user is added to the user table, then the preferences are all automatically set (for them to edit at a later time).
So far I have learnt how to add data to a table, but i'm struggling with:
As I am using more than one table should I use Magento's EAV way creating tables?
If simply adding two separate tables is acceptable how do I update the preferences table when the user table has been added to?
To keep with best practices where should my code go for adding to a table and extracting from a table (helpers, models etc...)?
WHAT I HAVE TRIED
I added the prefcentreoptions node and table to my config
<prefcentre_resource> <class>Ps_Prefcentre_Model_Resource</class> <entities> <prefcentre> <table>prefcentre</table> </prefcentre> <prefcentreoptions> <table>prefcentreoptions</table> </prefcentreoptions> </entities> </prefcentre_resource>
I added prefcentreoptions.php to the model folder
I added prefcentreoptions.php to the resource folder
I added a prefcentreoptions folder in the resource folder and added collection.php to that
I then tried to use
$prefs = Mage::getModel('prefcentreoptions/prefcentreoptions'); $prefs->setData('prefcentre_id', 1);
An error was thrown saying
Call to a member function setData() on a non-object
What have I done wrong
$prefs = Mage::getModel('prefcentreoptions/prefcentreoptions');
$prefs = Mage::getModel('prefcentre/prefcentreoptions');
the script move onto another error
Fatal error: Call to a member function beginTransaction() on a non-object in /Users/myname/Sites/magentoDevTest/app/code/core/Mage/Core/Model/Abstract.php on line 313
what information have I not provided to the script for it to continue?
(just incase it makes a difference)
The database i am writing to only requires one column to be completed the rest of the information will have default values which will be added