<![CDATA[ Custom database tables - what is wrong? - My Forums]]> https://forums.modx.com/thread/?thread=98351 <![CDATA[Custom database tables - what is wrong?]]> https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531774
I have used CMP Generator to connect my custom datatable with modx.
So now i have a schema:

<?xml version="1.0" encoding="UTF-8"?>
<model package="TinyStory" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
	<object class="Story" table="_story" extends="xPDOSimpleObject">
		<field key="author" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
		<field key="name" dbtype="varchar" precision="126" phptype="string" null="false" />
		<field key="story" dbtype="text" phptype="string" null="false" />
		<field key="lang" dbtype="varchar" precision="3" phptype="string" null="false" />
		<field key="fav" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" />
		<field key="date" dbtype="date" phptype="date" null="false" />
		<field key="next" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" />
		<field key="prev" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" />
	</object>
</model>


And i have a class:
<?php
class Story extends xPDOSimpleObject {}


All neccesery files are here: core/components/TinyStory/model/TinyStory/

So i have created a simple snippet to test if the connection is work (there is couple of rows in my databse with id =1 and 2):
<?php
$package_path = $modx->getOption('core_path').'components/TinyStory/model/';
$modx->addPackage('TinyStory', $package_path,'modx_');

$query = $modx->newQuery('Story');
$row = $modx->getObject('Story',1);

if($row==NULL)
{
$output="row is NULL";
}
else
{
$output="We have something! Wow!";
}

return $output;


But it's looks like "getObject('Story',1);" returns NULL.

What i am doing wrong?

Best regards, Paul]]>
osiris2000 Sep 19, 2015, 09:23 AM https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531774
<![CDATA[Re: Custom database tables - what is wrong?]]> https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531778 Quote from: Bruno17 at Sep 19, 2015, 02:39 PM
if your table is 'modx_story'

it should be table="story"

you don't need 'modx_' in your addPackage, since this is the default table-prefix.

and if you define null="false", you should also define a default-value

It works!

Thank you for your help, Bruno17!]]>
osiris2000 Sep 19, 2015, 10:29 AM https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531778
<![CDATA[Re: Custom database tables - what is wrong? (Best Answer)]]> https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531777
package="tinystory"


$package_path = $modx->getOption('core_path').'components/tinystory/model/';
]]>
Bruno17 Sep 19, 2015, 09:42 AM https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531777
<![CDATA[Re: Custom database tables - what is wrong? (Best Answer)]]> https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531776
it should be table="story"

you don't need 'modx_' in your addPackage, since this is the default table-prefix.

and if you define null="false", you should also define a default-value]]>
Bruno17 Sep 19, 2015, 09:39 AM https://forums.modx.com/thread/98351/custom-database-tables---what-is-wrong#dis-post-531776