coen-hyde/Shanty-Mongo — Issue #47: how to use MongoDBRef::create
Author: zapatista
Created: 2011-10-20 09:41:50+00:00
State: open

i've a model:

class Application_Model_Db_Table_ProfileAttribute extends Shanty_Mongo_Document
{
protected static $_db = 'test';
protected static $_collection = 'profileAttribute';

protected static $_requirements = array(
'attributeGuid' => array('Document:Application_Model_Db_Table_Attribute')
);
}

i try this:

$a = Application_Model_Db_Table_Attribute::one(array('guid'=>'fixedTitle'));

$data = array(
'_type' => array(
'Application_Model_Db_Table_ProfileAttribute',
'Application_Model_Db_Table_Attribute'
),
'profileGuid' => 'article',
'attributeGuid' => MongoDBRef::create('Application_Model_Db_Table_Attribute', new MongoId($a->getId())),
'defaultValues' => '',
'viewOrder' => 1
);

Application_Model_Db_Table_ProfileAttribute::insert($data, array('safe' => true));

result:

[attributeGuid] => Array
(
[$ref] => Application_Model_Db_Table_Attribute
[$id] => MongoId Object
(
[$id] => 4e9fa6b1ecb22fa00100009c
)

)

question:

how do i get $id, coz i try print_r($result->attributeGuid) it gave me NULL ?