First, let me point out my version: MODX Revolution 2.2.4-pl (June 14, 2012)
Okay, so now, what I'm trying to do is add a foreign key from my custom table, back to modx_site_content.
Here goes:
In modx_site_content, we have individual rows of tags. These are search keywords that we use to crawl twitter. The results from twitter, get stored in there as well, every things working great! Now, I'm tasked with finding a way to actually track the keywords. They want to know over time, what keywords are bringing back results, which ones aren't. My plan, which so far is somewhat working, was to create a new table, called "twitter_dataresults"
Structure looks like the following:
CREATE TABLE IF NOT EXISTS `twitter_dataresults` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`results` int(10) DEFAULT NULL,
`createdon` int(20) DEFAULT NULL,
`query_id` int(10) NOT NULL,
PRIMARY KEY (`id`),
KEY `query_id` (`query_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Simply, results will contain how many twitter results were returned for that particular search phrase. Createdon is the date.
Now, query_id is where I'm stuck, this is the foreign key that should map back to modx_site_content id for that particular search keyword.
Following this example, this is where I'm at:
http://bobsguides.com/custom-db-tables.html
Here is my schema for the table:
<?xml version="1.0" encoding="UTF-8"?>
<model package="twitter" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
<object class="Dataresults" table="dataresults" extends="xPDOSimpleObject">
<field key="results" dbtype="int" precision="10" phptype="integer" null="true" />
<field key="createdon" dbtype="int" precision="20" phptype="integer" null="true" />
<field key="query_id" dbtype="int" precision="10" phptype="integer" null="false" index="index" />
<index alias="query_id" name="query_id" primary="false" unique="false" type="BTREE" >
<column key="query_id" length="" collation="A" null="false" />
</index>
<aggregate alias="Resource" class="modResource" local="query_id" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>
Now, when I run the script to magically create the classes, etc, I can search or query data in that table, but it's not displaying the associated foreign key data.
Lastly, do I need to update the schema for modx_site_content to reflect the new table? Long term wise, I'd like to be able to view various keywords, and see all associated responses over time, to determine if the keywords are worth having or not.
I feel like I'm close, but have a feeling i'm not setting the aggregate alias correctly.