Skip to content

Instantly share code, notes, and snippets.

@coen-hyde
Created July 16, 2011 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coen-hyde/1086162 to your computer and use it in GitHub Desktop.
Save coen-hyde/1086162 to your computer and use it in GitHub Desktop.
Shanty Mongo references test
<?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