How can I map a field inside a document as associative array whose values are references to another document?
Let's say I have a document File
which represents some file on disk. Something like this:
/** @Document */
class File {
/** @Id */
protected $id;
/** @String */
protected $filename;
// Getter and setters omitted
}
And another document representing an image, which stores references to different sizes of an image. Something like this:
/** @Document */
class Image {
/** @Id */
protected $id;
/** ???? */
protected $files;
// Getter and setters omitted
}
I now want to be able to store some references to files in the image document keyed by their size. For exampl:
$file1 = new File('/some/path/to/a/file');
$file2 = new File('/some/path/to/another/file');
$image = new Image();
$image->setFiles(array('50x50' => $file1,'100x100' => $file2));
The resulting MongoDB document should look something like this:
{
"_id" : ObjectId("...."),
"files" : {
"50x50" : {
"$ref" : "files",
"$id" : ObjectId("...")
},
"100x100" : {
"$ref" : "files",
"$id" : ObjectId("...")
}
}
}
So how do I map the files
field in the Image
document?