Created
July 16, 2011 08:35
-
-
Save coen-hyde/1086162 to your computer and use it in GitHub Desktop.
Shanty Mongo references test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('ZEND_LIBRARY_DIR', '...'); | |
define('SHANTY_MONGO_LIB_DIR', '...'); | |
ini_set('include_path', SHANTY_MONGO_LIB_DIR . ':' . ZEND_LIBRARY_DIR . ':' . ini_get('include_path')); | |
require_once("Zend/Loader/Autoloader.php"); | |
$autoloader = Zend_Loader_Autoloader::getInstance(); | |
$autoloader->registerNamespace('Shanty_'); | |
$autoloader->setFallbackAutoloader(true); | |
class User extends Shanty_Mongo_Document { | |
protected static $_db = 'core'; | |
protected static $_collection = 'user'; | |
protected static $_requirements = array( | |
'username' => 'Required', | |
'email' => 'Required', | |
'roles' => array('DocumentSet'), | |
'roles.$' => array('Document:Role', 'AsReference') | |
); | |
} | |
class Role extends Shanty_Mongo_Document { | |
protected static $_db = 'core'; | |
protected static $_collection = 'role'; | |
protected static $_requirements = array( | |
'name' => 'Required' | |
); | |
} | |
$user = new User(array( | |
'username' => 'John', | |
'email' => 'john@john.com' | |
)); | |
$role = new Role(array( | |
'name' => 'admin' | |
)); | |
$user->save(); | |
$role->save(); | |
$user->roles->addDocument($role); | |
$user->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment