Hi Peeps,
I’m just starting out with modx revo and xpdo. I’m reasonably sorted with modx and building a site but I’ve fallen at the first hurdle with accessing my custom tables. I searched around and found
http://bobsguides.com/custom-db-tables.html and managed to create the xml scheema and class files and was able to successfully access a single table and retrieve data but fell over trying to join tables. I could retrieve data from the parent table but could not get the data from the child table. I checked my tables with SQL and all worked. I then tried
http://rtfm.modx.com/display/xPDO20/More+Examples+of+xPDO+XML+Schema+Files.
I used the tables defns to create the tables, reran bobs snippet to generate the schema and class code then pasted the new xml schema code into my schema and put snippet code on a resource. When I viewed the page it retrieved the data from the primary table but not the child table. If I run the code on the child table as a non join query i can retrieve data - just cann’t get the data from the join tables whn I run the join code.
What am I doing wrong - any advice gratefully received before I loose what little hair I have got left :’(.
This is the snippet code
$path = MODX_CORE_PATH . 'components/soshul/';
$result =$modx->addPackage('soshul',$path . 'model/','shl_');
$output = '';
if (! $result) {
return 'failed to add package';
} else {
$output = '<p>added Package</p>';
}
$output .='<p>below is the join results.</p>';
$blogpost = $modx->getObject('Blogposts', array('blogpost_id' => 1 ) );
$comments = $blogpost->getMany('Comments');
$output .= $blogpost->get('content');
foreach ( $comments as $c )
{
$output .= $c->get('comment');
}
//now test to see if i can retrieve from the comment table as a single table
$output .='<br /><br />';
$output .='<p>Below is the data from the child table so I can access it as a single table query:</p>';
$coms = $modx->getObject('Comments', array('comment_id' => 1 ) );
$output .='<p>';
$output .= $coms->get('comment');
$output .='</p>';
return $output;
This is the out put on the resource when viewed in browser
added Package
below is the join results.
This is blog post 1
Below is the data from the child table so I can access it as a single table query:
1 comment 1
below is the schema code
<object class="Blogposts" table="blogposts" extends="xPDOObject">
<field key="blogpost_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<field key="content" dbtype="text" phptype="string" null="true" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="blogpost_id" collation="A" null="false" />
</index>
<composite alias="Comments" class="Comments" local="blogpost_id" foreign="blogpost_id" cardinality="many" owner="local" />
</object>
<object class="Comments" table="comments" extends="xPDOObject">
<field key="comment_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<field key="blogpost_id" dbtype="int" precision="11" phptype="integer" null="true" />
<field key="comment" dbtype="text" phptype="string" null="true" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="comment_id" collation="A" null="false" />
</index>
<aggregate alias="Blogposts" class="Blogposts" local="blogpost_id" foreign="blogpost_id" cardinality="one" owner="foreign" />
</object>