<model package="jaylearn" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM"> <object class="jlUser" table="users" extends="modUser"> <composite alias="Data" class="jlUserData" local="id" foreign="user_id" cardinality="one" owner="local" /> </object> <object class="jlUserData" table="userdata" extends="xPDOObject"> <field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" /> <field key="school_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" /> <field key="salutation" dbtype="varchar" precision="255" phptype="string" null="true" index="index" /> <aggregate alias="User" class="jlUser" local="user_id" foreign="id" cardinality="one" owner="foreign" /> <composite alias="School" class="jlSchool" local="school_id" foreign="id" cardinality="one" owner="local" /> </object> <object class="jlSchool" table="schools" extends="xPDOObject"> <field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" /> <field key="name" dbtype="varchar" phptype="string" null="true" /> <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true"> <column key="id" collation="A" null="false" /> </index> <composite alias="UserData" class="jlUserData" local="id" foreign="school_id" cardinality="many" owner="local" /> </object> </model>
$base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/jaylearn/';
$modx->addPackage('jaylearn',$base_path.'model/', "jl_");
$newUser = $modx->newObject('jlUser');
$newUser->fromArray(array(
'username' => 'newuser',
'password' => 'password',
'class_key' => 'jlUser',
));
$newProfile = $modx->newObject('modUserProfile');
$newProfile->set('fullname', 'New User');
$newProfile->set('email', '[email protected]');
$newData = $modx->newObject('jlUserData');
$newData->set('salutation', 'Mr');
$newUser->addOne($newProfile);
$newUser->addOne($newData, 'Data');
$newUser->save();
[2011-09-16 23:15:36] (ERROR @ /index.php) No foreign key definition for parentClass: modUser using relation alias: Data
[2011-09-16 23:17:01] (ERROR @ /connectors/security/user.php) Could not get table class for class: modAccess
[2011-09-16 23:17:01] (ERROR @ /connectors/security/user.php) Could not get table name for class: modAccess
[2011-09-16 23:17:01] (ERROR @ /connectors/security/user.php) Error 42000 executing statement:
Array
(
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 38' at line 1
)
[2011-09-16 23:17:01] (ERROR @ /connectors/security/user.php) Error 42S02 executing statement:
Array
(
[0] => 42S02
[1] => 1146
[2] => Table 'jaylearn_modx.modx_userdata' doesn't exist
)
[2011-09-16 23:17:15] (ERROR @ /index.php) Error 42S02 executing statement:
INSERT INTO `jl_users` (`username`, `password`, `cachepwd`, `class_key`, `active`, `hash_class`, `salt`) VALUES ('newuser', 'NTiGQBjLFnw3NQwATf1y0lQMvT6NWpsvjQkoxRuMTL4=', '', 'jlUser', 1, 'hashing.modPBKDF2', 'e989c82f51caf063b65167bd946caba5')
Array
(
[0] => 42S02
[1] => 1146
[2] => Table 'jaylearn_modx.jl_users' doesn't exist
)This question has been answered by opengeek. See the first response.
Table 'jaylearn_modx.modx_userdata' doesn't existWell, does it, the schema definition above doesn't create the tables for you.
[2011-09-17 08:22:41] (ERROR @ /index.php) Error 42S02 executing statement:
INSERT INTO `jl_users` (`username`, `password`, `cachepwd`, `class_key`, `active`, `hash_class`, `salt`) VALUES ('newuser', 'Mv/iAPyyKsQD1FDm5iK2QQ2pDH2/PBSEWZzrO9dHEjo=', '', 'jlUser', 1, 'hashing.modPBKDF2', '685625e6468d8e3713f6aab5c4318984')
Array
(
[0] => 42S02
[1] => 1146
[2] => Table 'jaylearn_modx.jl_users' doesn't exist
)<object class="modJlUser" table="jl_users" extends="modUser">
<model package="jaylearn" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM"> <object class="jlUser" table="users" extends="modUser"> <composite alias="Data" class="jlUserData" local="id" foreign="user_id" cardinality="one" owner="local" /> </object> <object class="jlUserData" table="jl_userdata" extends="xPDOObject"> <field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" /> <field key="school_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" /> <field key="salutation" dbtype="varchar" precision="255" phptype="string" null="true" index="index" /> <aggregate alias="User" class="jlUser" local="user_id" foreign="id" cardinality="one" owner="foreign" /> <composite alias="School" class="jlSchool" local="school_id" foreign="id" cardinality="one" owner="local" /> </object> <object class="jlSchool" table="jl_schools" extends="xPDOObject"> <field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" /> <field key="name" dbtype="varchar" phptype="string" null="true" /> <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true"> <column key="id" collation="A" null="false" /> </index> <composite alias="UserData" class="jlUserData" local="id" foreign="school_id" cardinality="many" owner="local" /> </object> </model>
$base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/jaylearn/';
$modx->addPackage('jaylearn',$base_path.'model/', 'modx_');
$newUser = $modx->newObject('jlUser');
$newUser->fromArray(array(
'username' => 'seconduser',
'password' => 'password',
'class_key' => 'jlUser',
));
$newProfile = $modx->newObject('modUserProfile');
$newProfile->set('fullname', 'Second User');
$newProfile->set('email', '[email protected]');
$newData = $modx->newObject('jlUserData');
$newData->set('salutation', 'Dr');
$newUser->addOne($newProfile, 'Profile');
$newUser->addOne($newData, 'Data');
$newUser->save();
//echo out some details of the new user
//note: getData is a custom method added to the jlUser class and simply returns $user->getOne('Data');
echo "<br/>User created: ".$newUser->getData()->get('salutation').' '.$newUser->getOne('Profile')->get('fullname');
[2011-09-17 13:59:31] (ERROR @ /connectors/security/user.php) Could not get table class for class: modAccess
[2011-09-17 13:59:31] (ERROR @ /connectors/security/user.php) Could not get table name for class: modAccess
[2011-09-17 13:59:31] (ERROR @ /connectors/security/user.php) Error 42000 executing statement:
Array
(
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 47' at line 1
)