Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedded document and php assiociative array, how to in mongodb with doctrine?
    text
    copied!<p>Hi after some hours of searching i finally give up, I cant find any way of getting this thing done, I want to know if it is possible to create an EmbedMany relation using an php assiociative array.</p> <p>I can use the @field(type="hash") but then I cant add a Embedded document to that key!</p> <p>Here is the code I have now:</p> <pre><code>&lt;?php namespace Entity; /** * @Document(collection="object_types") */ class OType { /** * @Id * @var integer */ private $id; /** * @Field(type="string") * @var string */ private $name; /** * @EmbedMany(targetDocument="Property") */ private $properties = array(); /** * Node Type * * @param string $name */ public function __construct($name) { $this-&gt;name = $name; } /** * Set name * * @param string $name * @return void */ public function setName($name) { $this-&gt;name = $name; } /** * Get name * * @return string */ public function getName() { return $this-&gt;name; } /** * Add property * * @param Property $property */ public function addProperty(Property $property) { $this-&gt;properties[$property-&gt;getName()] = $property; } /** * Get properties * * @return Property[] */ public function getProperties() { return $this-&gt;properties; } } </code></pre> <p>I want to do something like this:</p> <pre><code>$property = new Property(); $property-&gt;setName('memberof'); $property-&gt;setType('string'); $type = new OType(); $type-&gt;setName('user'); $type-&gt;addProperty($property); </code></pre> <p>And get this result:</p> <pre><code>{ "_id": { "$oid": "4d89ae2c2eea0f8406000004" }, "name": "user", "properties": [ "memberof": { "name": "memberof", "type": "string" } ] } </code></pre> <p>Thanks for you help. </p> <p>Best regards Flamur</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload