UnionOfRAD/lithium — Issue #357: Updating embedded document with timestamp / MongoDate
Author: Necsord
Created: 2012-02-26 16:11:27+00:00
State: open

Updating embedded document with timestamp / MongoDate

* Pastium:
* [Controller](http://pastium.org/view/7c19b898563410ab9496c37087222ebc)
* [Users model](http://pastium.org/view/7c19b898563410ab9496c370872249bc)
* [Warnings model](http://pastium.org/view/7c19b898563410ab9496c37087224517)
* [Fork where I tested](https://github.com/Necsord/framework/blob/master/app/controllers/IndexController.php)

Pretty much 3 files controller and two models.

The paste should be self explanatory but basically I'm trying to empty embedded document in Users object and then reinsert the same data with different timestamp in one of the fields as Warnings model object.

Users model has only two fields `_id` and `warnings` which is an array. Warnings model has three fields `_id`, `user_id` (`MongoId`) and `created` (`MongoDate`).

The problem is that although I'm doing the same exact things (Simple tteration over the process with changing `time()` as the only difference) sometimes ( seems like with certain timestamps ) timestamp isn't cast to MongoDate and when that happens user_id isn't cast to the `MongoId` as well.

I tried checking the query in `\lithium\data\Model::save()` but it seemed fine. `_data` and `_original` had timestamp while `_updated` had an `MongoDate` object. I could have missed something though.

I wanted to do a proper test case for this but seeing as I didn't do many things with mocks I decided to give up with that for now.