I am using the Lithium PHP Framework - with MongoDB database - to create some input/edit forms for my application.
I'm using the concept of embedded documents in MongoDB. It took me a bit of tuning to get the initial save to work, but I have it set up so it is working properly.
When I look in MongoDB - my object looks as follows:
{
_id: "5119951516c19",
level_name: "Testing",
questions: [
{
question_id: "5119951516cb5",
question_text: "Why is the sky blue"
},
{
question_id: "5119951516cc3",
question_text: "Why is grass green"
}
]
}
Now, if I want to do a very simple edit, such as:
$level = Levels::find($id);
$level["level_name"] = "Testing - UPDATE";
$level->save();
The good news is that the field in question saves. But, the bad news is that it destroys my entire object model. The new object model in MongoDB gets saved as follows:
{
0: {
question_id: "5119951516cb5",
question_text: "Why is the sky blue"
},
1: {
question_id: "5119951516cc3",
question_text: "Why is grass green"
},
_id: "5119951516c19",
level_name: "Testing - UPDATE",
questions: [
{
question_id: "5119951516cb5",
question_text: "Why is the sky blue"
},
{
question_id: "5119951516cc3",
question_text: "Why is grass green"
}
]
}
The basic doc remained the same - but somehow the embedded docs got thrown to the top level under the keys "0" and "1".
I've searched high and low and I can't figure out why this is happening. Since my save function is so simple, I am assuming this is a bug in Lithium. Which is fine - as long as there is a way I can get around it.
Thanks in advance.