I am trying to create an associative array of embedMany relationship with string keys for example I have a Document class named sampleDocument
and it has an EmbedMany relationship on the field price
.
this is how I am setting the price field with associative array with string keys:
$obj->setPrice(array('key1' => $priceObjOne, 'key2' => $priceObj2));
it insert that data into the mongo as follows:
{
"prices": [
{/*Price Object*/}, { /*Price Object*/ }
]
}
What I am trying to do is to have a string key for each one. it already has the string key in the array. but it doesn't insert it into the Mongo. how can I get passed it?
You need to define "prices" as @Hash type in your object. With “type” attribute set to “hash”, Doctrine will store and retrieve the value as an associative array:
<?php
class SampleDocument
{
/** @Hash */
protected $prices = array();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.