coen-hyde / Shanty-Mongo

Shanty Mongo is a mongodb library for the Zend Framework. Its intention is to make working with mongodb documents as natural and as simple as possible. In particular allowing embedded documents to also have custom document classes.
Other
200 stars 52 forks source link

Issue setting AsReference object through property after object serialized #41

Open tholder opened 13 years ago

tholder commented 13 years ago

Seems to be a bit of a bug/niggle when setting an object using a property setter. The following works:

            $data = array();
            $data['appName'] = $this->_getParam('appName');
            $data['urlKey'] = $this->_getParam('urlKey');
            $data['owner'] = $this->company;
            $data['createdBy'] = $this->user;

            $app = new Model_Mongo_Application($data);
            $app->save();

The following doesn't:

            $app = new Model_Mongo_Application();
            $app->appName = $this->_getParam('appName');
            $app->urlKey = $this->_getParam('urlKey');
            $app->owner = $this->company;
            $app->createdBy = $this->user;
            $app->save();

It produces:

Shanty_Mongo_Exception: Property 'owner' must not be null. in /Users/tholder/Sites/listenablefe/library/Shanty/Mongo/Document.php on line 805

Model is defined with requirements like:

protected static $_requirements = array(
    'appName' => array('Required'),
    'urlKey' => array('Required'),
    'owner' => array('Document:Model_Mongo_Company', 'AsReference', 'Required'),
    'createdBy' => array('Document:Model_Mongo_User', 'AsReference', 'Required')
);
coen-hyde commented 13 years ago

Hi Tom,

That's weired, but I'd wagger that something else must be going on. This stuff is pretty well tested. I assume $this->company is an instantiated shanty document object?

tholder commented 13 years ago

Yes it is. I will try and get to the bottom of it when I get a mo. Possibly because $this->company has been passed over session.

Cheers Tom

On 9 Oct 2011, at 01:26, Coen Hydereply@reply.github.com wrote:

Hi Tom,

That's weired, but I'd wagger that something else must be going on. This stuff is pretty well tested. I assume $this->company is an instantiated shanty document object?

Reply to this email directly or view it on GitHub: https://github.com/coen-hyde/Shanty-Mongo/issues/41#issuecomment-2334551

coen-hyde commented 13 years ago

Ah, yes, there would be an issue with sleeping and wakeup. Infact there aren't any sleep or wake up methods. It shouldn't be too hard to implement i'd say.

tholder commented 13 years ago

Actually, not sure this is as simple as that, I've removed the serialization and loaded a new object on each page.

$this->company is actually an object that comes from the user document.

$this->user is defined like:

protected static $_requirements = array(
    'username' => array('Required'),
    'forename' => array('Required'),
    'email' => array('Required'),
    'secret' => array('Required'),
    'companies' => array('DocumentSet'),
    'companies.$' => array('Document:Model_Mongo_UserCompanyAccess')
);

And $this->company is pulled from the companies documentset.

Model_Mongo_UserCompanyAccess is defined like:

protected static $_requirements = array(
    'company' => array('Document:Model_Mongo_Company', 'AsReference'),
    'isPrimary' => 'Required'
);

So, when a user has a document set with objects that are AsReference, does it need to refresh them some how?