I am trying to add a mapping information in Symfony2 using MongoDB as shown here : http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html [at the Adding Information section] But what I want to do is to add an embedded documents as well. Here is a part of my document with embedded documents :
"_id" : "",
"last_name" :,
"first_name" : "",
"address" : [
{
"Street" : "",
"City" : "",
"Zip_Code" : "",
"Country": ""
}
],
"company" : ""
"purshaed_items" : [
{
"items_id" : "",
"category":"",
"price":"",
"date_of_purshae"
}
]
So as you can see I have the fields "Address" & "Purshaed_items" that are embedded documents. I found this link http://doctrine-orm.readthedocs.org/projects/doctrine-mongodb-odm/en/latest/reference/embedded-mapping.html I guess that my case will be the "Embed Many" but didn't really get how it works?
Can someone please try to explain how it works?
Thank you
I would make it like this:
Assuming that you have another document class named PurshaedItem (PurchasedItem perhaps).
And the target document would be mapped like this:
And if you want to query for embedded documents, you can get it in controller (recommended), here is my simple example.
For getting it in twig template, here is another example.
The examples are from simple Symfony blog application. There are 3 documents: Post, Tag, and Comment. Post has Tags and Comments as embedded properties. Take a look around the code, it is simple. If the answer has been useful to you, please click to accept it.